我找不到解决方案。我的图像形状是 128*128*3,它有三个通道,但也会导致错误
文件“E:/ML/keras_test/vgg.py”,第 30 行,在 load_data data[i,:,:,:] = arr
ValueError:无法将输入数组从形状(128,128)广播到形状(128,128,3)
我的代码如下:
def load_data(path):
data = np.empty((12755,128,128,3),dtype="uint8")
label = np.empty((12755,),dtype="uint8")
imgs = []
imgs_name = []
for each_person in os.listdir(path):
temp = os.path.join(path,each_person)
for each_image in os.listdir(temp):
imgs.append(temp + "\\" + each_image)
imgs_name.append(each_image)
num = len(imgs)
for i in range(num):
img = Image.open(imgs[i])
arr = np.asarray(img,dtype="uint8")
print arr.shape
data[i,:,:,:] = arr
label[i] = int(imgs_name[i].split('.')[0])
print 'load_data is ok!' + str(data.shape[0])
return data,label