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)
我真心不懂,只是换了其他图片加载,为什么就报错,真心求教!
我在想是不是我的猫狗图片出了问题,但看了也感觉没什么问题啊,头痛