我试图使图像增强,看看它将如何影响模型,但由于某种原因,我得到了这个错误
TypeError: '>' not supported between instances of 'int' and 'ImageDataGenerator'
我使用efficientNetb4并添加了自己的分类器层。
augment = ImageDataGenerator(horizontal_flip=True, vertical_flip=True, rotation_range=30, validation_split=0.15)
train = augment.flow_from_directory(path, target_size=(380,380), batch_size=35, subset='training')
valid = augment.flow_from_directory(path, target_size=(380,380), batch_size=35, subset='validation')
base_model = keras.applications.EfficientNetB4(weights="imagenet",include_top=False, input_shape=(380, 380,3))
for layer in base_model.layers:
layer.trainable = False
avg = keras.layers.GlobalAveragePooling2D()(base_model.output)
output = keras.layers.Dense(3, activation="softmax")(avg)
model = keras.Model(inputs=base_model.input, outputs=output)
earlystopping = keras.callbacks.EarlyStopping(monitor='loss', patience=3)
optimizer = keras.optimizers.SGD(learning_rate=0.001, momentum=0.9, decay=0.0001)
model.compile(loss="sparse_categorical_crossentropy",optimizer=optimizer,metrics=["accuracy"])
history = model.fit_generator(train, augment, validation_data=valid, epochs=25, verbose=2, callbacks=[earlystopping])
我认为问题出在我指定的batch_size
上,但无法理解它是否导致了此错误
1条答案
按热度按时间1qczuiv01#
请检查fit_generator(https://faroit.com/keras-docs/1.2.0/models/model/)的文档:
第二个参数是'samples_per_epoch',它是int,但是您传递的是ImageDataGenerator。因此出现了错误消息。我不明白为什么您需要在这里传递'augment'。下面的代码应该可以工作: