qq_42712782 2018-11-13 13:42 采纳率: 0%
浏览 10560

ValueError: could not broadcast input array from shape (100,100,3) into shape (100,100)

path是图片的路径 w,h是图片的设定长宽

```def read_img(path):
cate=[path+x for x in os.listdir(path) if os.path.isdir(path+x)]
imgs=[]
labels=[]
for idx,folder in enumerate(cate):
for im in glob.glob(folder+'/*.jpg'):
print('reading the images:%s'%(im))
img=io.imread(im)
img=transform.resize(img,(w,h))
imgs.append(img)
labels.append(idx)
return np.asarray(imgs,np.float32),np.asarray(labels,np.int32)

data,label=read_img(path)

我运行花卉图片加载的时候无错误,但换个路径运行猫狗识别的时候就报错
  File "C:/Users/spirit/Desktop/实验练习/tensorflow/猫狗识别/训练模型/猫狗识别.py", line 34, in <module>data,label=read_img(path)

  File "C:/Users/spirit/Desktop/实验练习/tensorflow/猫狗识别/训练模型/猫狗识别.py", line 31, in read_img
    return np.asarray(imgs,np.float32),np.asarray(labels,np.int32)

  File "D:\Anaconda\envs\tensorflow\lib\site-packages\numpy\core\numeric.py", line 501, in asarray
    return array(a, dtype, copy=False, order=order)
        ValueError: could not broadcast input array from shape (100,100,3) into shape (100,100)

我真心不懂,只是换了其他图片加载,为什么就报错,真心求教!
我在想是不是我的猫狗图片出了问题,但看了也感觉没什么问题啊,头痛
  • 写回答

2条回答

  • 不怕码代码 2019-02-25 13:49
    关注

    图片问题, 有的图片颜色空间是 Grey 的,imread 读出的数据是(100,100),和正常RGB 图片读出的 (100,100,3)无法合并成同类型数据

    可以尝试 一下 io.imread(im, as _grey=true),我是直接把 grey 的图片删除了

    评论

报告相同问题?

悬赏问题

  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题