ValueError:无法将形状(128,128,3)的输入数组广播为形状(128,128) [英] ValueError: could not broadcast input array from shape (128,128,3) into shape (128,128)

查看:2498
本文介绍了ValueError:无法将形状(128,128,3)的输入数组广播为形状(128,128)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我正在构建一个图像分类器,这个代码的一小部分
在这个部分中尝试'img_data_list'是一个数组,我将这个数组转换为np.array但是
( img_ data = np.array(img_data_list))
这行代码给我一个错误
(无法将形状(128,128,3)的输入数组广播成形状(128,128))我不知道为什么这个正在发生

hi I am building an image classifier and this an small part of my code in this part m trying to 'img_data_list' is an array and I am converting this array into np.array but (img_ data = np.array(img_data_list)) this line of code giving me an error (could not broadcast input array from shape (128,128,3) into shape (128,128)) i dont know why this is happening

for dataset in data_dir_list:
    img_list=os.listdir(data_path+'/'+ dataset)

    print ('Loaded the images of dataset-'+'{}\n'.format(dataset))

    for img in img_list:
        image_path = os.path.join(data_path, dataset, img)

        input_img=cv2.imread(image_path)

        if input_img is not None:
            input_img_resize=cv2.resize(input_img,(128,128))
            img_data_list.append(input_img_resize)

        else:
            print(img+' image didnt read')

img_data = np.array(img_data_list)
img_data = img_data.astype('float32')
img_data /= 255


推荐答案

我发现解决方案中的一些图像在删除后,数据集中的图像被破坏了分类器工作正常

I found the solution some images are corrupted in dataset after removing them classifier is working perfectly

这篇关于ValueError:无法将形状(128,128,3)的输入数组广播为形状(128,128)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆