filepath = "model.h5" checkpoint = ModelCheckpoint(filepath, monitor='val_top_3_accuracy', verbose=1, save_best_only=True, mode='max') reduce_lr = ReduceLROnPlateau(monitor='val_top_3_accuracy', factor=0.5, patience=2, verbose=1, mode='max', min_lr=0.00001) callbacks_list = [checkpoint, reduce_lr] #datagen.flow(x_train,y_train, batch_size=batch_size) history = model.fit_generator(datagen.flow(x_train, y_train, batch_size=batch_size, target_size=(100, 125)), class_weight=class_weights, validation_data=(x_validate,y_validate),steps_per_epoch=x_train.shape[0] // batch_size, epochs=10, verbose=1, callbacks=callbacks_list)这一段代码报错TypeError: flow() got an unexpected keyword argument 'target_size'
时间: 2024-02-14 12:18:09 浏览: 75
很抱歉,我之前的回答并不正确,`target_size`参数适用于`ImageDataGenerator`,而不是`DataGenerator`。对于`DataGenerator`,你可以在实例化时指定输入数据的形状,例如:
```
train_generator = DataGenerator(x_train, y_train, batch_size=batch_size, input_shape=(100, 125, 1))
val_generator = DataGenerator(x_validate, y_validate, batch_size=batch_size, input_shape=(100, 125, 1))
```
这里我假设输入数据的形状是`(100, 125, 1)`,并使用`input_shape`参数在实例化`DataGenerator`时指定。请注意,这里的`batch_size`应该与你在`fit_generator()`中使用的`batch_size`一致。
然后,将`fit_generator()`中的生成器修改为`train_generator`和`val_generator`:
```
history = model.fit_generator(train_generator,
class_weight=class_weights,
validation_data=val_generator,
steps_per_epoch=x_train.shape[0] // batch_size,
epochs=10,
verbose=1,
callbacks=callbacks_list)
```
阅读全文