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

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 的图片删除了

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog