0
votes

I couldn't find the solution.My image shape is 128*128*3,it has three channel,but it also cause the error

File "E:/ML/keras_test/vgg.py", line 30, in load_data data[i,:,:,:] = arr

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

My code as below:

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
1

1 Answers

0
votes

You are trying to put the original data into a small package, which is impossible. I think you are trying to transfer a image which has RGB channel into a gray scale image which has one channel. Try

datum = (imgs.sum(axis=2) / 3).reshape((12755, -1))

The resulting datum is a 12755 x 16384 array.