简体   繁体   English

Tensorflow 无法容纳图像列表

[英]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.我在 Tensorflow 上找到的与图像相关的教程都没有单独导入/处理图像,因此它们没有告诉我数据集应该是什么样子。

The model seems to be right since tf.keras.utils.plot_model shows me the correct plot.该模型似乎是正确的,因为 tf.keras.utils.plot_model 向我展示了正确的情节。 Also, traceback shows that the problem starts at model.fit.此外,回溯显示问题始于model.fit。

在对代码进行了更多研究之后,使用 Numpy 将图像列表转换为数组解决了该问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM