Reputation: 1751
I have the following function for reading images from the SO:
from keras.preprocessing import image as kimage
from keras.applications.vgg16 import preprocess_input
def read_image(path):
img = kimage.load_img(path, target_size=(224, 224))
tmp = kimage.img_to_array(img)
tmp = np.expand_dims(tmp, axis=0)
tmp = preprocess_input(tmp)
return tmp
And I create the following data generator that basically iterates my path strings and call the previous function. I want to call read image function and stack its output into a numpy array that I can input to keras fit function. I am using this code:
batch_holder = np.zeros((batch_size, 224, 244, 3))
for j, row in batch.iterrows():
batch_holder[j, :] = read_image(row['path'])[0]
But this does not work and I am receiving the following error which I consider as impossible to interpret:
File "train.py", line 71, in data_generator batch_holder[j, :] = read_image(row['path'])[0] ValueError: could not broadcast input array from shape (224,224,3) into shape (224,244,3)
What I am doing wrong?
Upvotes: 0
Views: 1477
Reputation: 71
Have you written 244 instead of 224 by mistake maybe?
batch_holder = np.zeros((batch_size, 224, 244, 3))
Upvotes: 2