[英]ImageDataGenerator from Keras returns `TypeError: data type not understood`
I create train and test dataset using Keras ImageDataGenerator.flow_from_directory(...).我使用 Keras ImageDataGenerator.flow_from_directory(...) 创建训练和测试数据集。 Then I want to use these data fit
model.fit()
.然后我想使用这些数据拟合
model.fit()
。 In Tensorflow 2.1 it works perfectly fine.在 Tensorflow 2.1 中它工作得非常好。 However, running the same code in Tensorflow 2.2 generates:
TypeError: data type not understood
.但是,在 Tensorflow 2.2 中运行相同的代码会生成:
TypeError: data type not understood
understand 。 How would you suggest to overcome this issue and run it TF2.2?您建议如何克服此问题并运行 TF2.2?
Code sample:代码示例:
train_gen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1. / 255., dtype=tf.float32)
train_data = train_gen.flow_from_directory(directory=os.path.join(current_dir, data, 'train/'), target_size=(width, height), class_mode='sparse')
...
model.fit(train_data, epochs=50) # This generates an error in TF2.2, but in TF2.1 works fine.
Another way of generating this error in TF2.2 is iterating over the generator:在 TF2.2 中生成此错误的另一种方法是迭代生成器:
train_gen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1. / 255., dtype=tf.float32)
train_data = train_gen.flow_from_directory(directory=os.path.join(current_dir, data, 'train/'), target_size=(width, height), class_mode='sparse')
for x,y in train_data:
print(type(x), type(y))
The problem was with keras versions.问题出在 keras 版本上。 The following configuration caused an error.
以下配置导致错误。
keras 2.3.1
keras-preprocessing 1.1.2
After changing to this versions everything works fine:更改为此版本后,一切正常:
keras 2.4.3
keras-preprocessing 1.1.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.