Reputation: 23
I'm using model.fit_generator() to predict images. i keep on receiving the following error:
ValueError: Error when checking input: expected conv2d_29_input to have 4 dimensions, but got array with shape (224, 224, 3) I'm trying to save the predicted images to a folder.
following is my code:
data_list = []
batch_index = 0
while batch_index <= train_generator.batch_index:
data = next(train_generator)
data_list.append(data[0])
batch_index = batch_index + 1
for i in range(batch_index):
for j in range(batch_size):
predicted[i][j]= model.predict(data_list[i] [j])
plt.imsave(os.path.join(path,'new_image'+ str(i)+ str(j)+ "_AE_.tiff"), predicted[i][j])
what is the problem with the shape?? thanks
Upvotes: 0
Views: 255
Reputation: 23
following is how i solved the problem:
path='the data folder'
data_list = []
batch_index = 0
predicted=[]
n= len(train_generator)
while batch_index <= train_generator.batch_index:
data = train_generator.next()
data_list.append(data[0])
batch_index = batch_index + 1
data_array = np.array(data_list, dtype= float)
predicted=model.predict(data_array)
for i in range(n):
plt.imsave(os.path.join(path,'new_image'+ str(i)+"_AE.tiff"), predicted[i,])
Upvotes: 0