我们可以只使用 model.fit 而不是 model.fit_generator 吗?
Can we use model.fit only instead of model.fit_generator?
我正在尝试使用 Keras 的 ImageDataGenerator,我想使用 model.fit 而不是 model.fit_generator ,我想摆脱以下语句,即:- steps_per_epoch和 validation_steps。
它会工作吗?它是否也动态地增加数据?
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory(train_path,
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory(valid_path,
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
#flow from directory is the method of imagedatagenerator
checkpoint_callback = ModelCheckpoint(filepath='CNN MobileNet.h5',monitor='val_accuracy', mode='max', save_best_only=True)
history=model.fit_generator(training_set,validation_data=(test_set),epochs=10,steps_per_epoch=len(training_set)
,validation_steps=len(test_set),callbacks=[checkpoint_callback])
# history=model.fit(training_set,validation_data=(test_set),epochs=10,callbacks=[checkpoint_callback])
.fit is used when the entire training dataset can fit into the memory
and no data augmentation is applied.
.fit_generator is used when either we have a huge dataset to fit into our memory or when data augmentation needs to be applied.
来源:https://www.geeksforgeeks.org/keras-fit-and-keras-fit_generator/
所以,在使用ImageDataGenerator时需要fit_generator
.fit 当整个训练数据集可以放入内存并且不应用数据扩充时使用。
fit_generator 当我们有一个巨大的数据集来适应我们的记忆或需要应用数据扩充时使用。
所以,在使用ImageDataGenerator时需要fit_generator。
我正在尝试使用 Keras 的 ImageDataGenerator,我想使用 model.fit 而不是 model.fit_generator ,我想摆脱以下语句,即:- steps_per_epoch和 validation_steps。 它会工作吗?它是否也动态地增加数据?
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory(train_path,
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory(valid_path,
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
#flow from directory is the method of imagedatagenerator
checkpoint_callback = ModelCheckpoint(filepath='CNN MobileNet.h5',monitor='val_accuracy', mode='max', save_best_only=True)
history=model.fit_generator(training_set,validation_data=(test_set),epochs=10,steps_per_epoch=len(training_set)
,validation_steps=len(test_set),callbacks=[checkpoint_callback])
# history=model.fit(training_set,validation_data=(test_set),epochs=10,callbacks=[checkpoint_callback])
.fit is used when the entire training dataset can fit into the memory and no data augmentation is applied.
.fit_generator is used when either we have a huge dataset to fit into our memory or when data augmentation needs to be applied.
来源:https://www.geeksforgeeks.org/keras-fit-and-keras-fit_generator/
所以,在使用ImageDataGenerator时需要fit_generator
.fit 当整个训练数据集可以放入内存并且不应用数据扩充时使用。
fit_generator 当我们有一个巨大的数据集来适应我们的记忆或需要应用数据扩充时使用。
所以,在使用ImageDataGenerator时需要fit_generator。