我正在使用Tensorflow Keras在Google Colab上使用fit_generator()在ImageDataGenerator批次中训练二进制Sigmoid分类CNN模型。由于某种原因,模型似乎要训练到完成之前的1步,然后再训练。这发生在每个时代。
https://i.stack.imgur.com/nGBBs.png
可能是什么原因?是在浪费时间吗?应该解决吗?
谢谢
编辑:模型是顺序的。
训练数据生成器:
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rescale = 1./255,
rotation_range = 40,
width_shift_range = 0.2,
height_shift_range = 0.2,
shear_range = 0.1,
zoom_range = 0.2,
fill_mode = 'nearest',
horizontal_flip = True,
vertical_flip = True,
validation_split=0.2
)
data_dir = '/tmp/sorted_images'
train_gen = train_datagen.flow_from_directory(
data_dir,
batch_size=128,
target_size = (96,96),
color_mode="grayscale",
class_mode = 'binary',
shuffle=True,
subset='training'
)
验证数据生成器:
from keras_preprocessing.image import ImageDataGenerator
valid_datagen = ImageDataGenerator(
rescale = 1./255,
validation_split=0.2
)
valid_gen = valid_datagen.flow_from_directory(
data_dir,
batch_size=128,
target_size = (96,96),
color_mode="grayscale",
class_mode = 'binary',
shuffle=True,
subset='validation'
)
model.compile(loss='binary_crossentropy', optimizer=adam, metrics=['accuracy', tf.keras.metrics.TruePositives(name='truepos'), tf.keras.metrics.FalseNegatives(name='falseneg'), tf.keras.metrics.FalsePositives(name='falsepos'), tf.keras.metrics.TrueNegatives(name='trueneg')])
history = model.fit_generator(train_gen, epochs=15, verbose = 1, callbacks=cb_list, validation_data = valid_gen, validation_freq = 5)