Avatrin
Avatrin

Reputation: 187

Tensorflow cannot fit a list of images

I have a spreadsheet with data. Each row is associated with a locally stored image. Together, they make up my training sets.

The images repeat; That is, each row does not have its own unique image. So, I have been trying to train the model by splitting up the dataset by image (that makes a lot of the other coding easier as well). I have been trying a lot of different things, and nothing seems to work. Currently, I am stuck here:

img = tf.image.decode_jpeg(image) # PIL img to tensor
images = [img]*len(training.values)
model.fit(
{"images": images, "data": training.values},
labels.values,
epochs=5)

This gives me the error:

AttributeError: 'list' object has no attribute 'shape'

I have no idea how to make progress. None of the image related tutorials I find on Tensorflow are importing/processing images individually, so they tell me nothing about what the dataset is supposed to look like.

The model seems to be right since tf.keras.utils.plot_model shows me the correct plot. Also, traceback shows that the problem starts at model.fit.

Upvotes: 0

Views: 248

Answers (1)

Avatrin
Avatrin

Reputation: 187

After playing a bit more around with the code, turning the list of images into an array with Numpy solved the problem:

images = np.array([img]*len(training.values))

Upvotes: 1

Related Questions