为什么 Keras 运行 在 25 个 epoch 中只有 5 个?
Why does Keras run only 5 epochs out of 25?
我已经卸载了 Keras 和 Tensorflow,并使用
安装了它们
pip install tensorflow == 2.6
pip install keras == 2.6
但即使在之后,我仍然有一件奇怪的事,它只有 5 个 epoch 运行ning:
我无法追踪这种情况是何时发生的,但它曾经 运行 所有时期。
这是我的代码:
train_datagen = ImageDataGenerator(rescale = 1.0/255.)
test_datagen = ImageDataGenerator(rescale = 1.0/255.)
train_generator = tf.keras.utils.image_dataset_from_directory(base_dir,
batch_size=20,
label_mode='categorical',
validation_split = 0.2,
subset='training',
seed=123,
image_size=(200, 200))
validation_generator = tf.keras.utils.image_dataset_from_directory(base_dir,
batch_size=20,
label_mode='categorical',
validation_split = 0.2,
subset='validation',
seed=123,
image_size=(200, 200))
model = Sequential([
Conv2D(32, (3, 3), activation='relu', input_shape=(200, 200, 3)),
MaxPooling2D((2, 2)),
Conv2D(64, (3, 3), activation='relu'),
MaxPooling2D((2, 2)),
Conv2D(128, (3, 3), activation='relu'),
tf.keras.layers.Dropout(0.2),
Flatten(),
Dense(256, activation='relu'),
Dense(4, activation='softmax')
])
model.compile(optimizer='Adam',
loss='categorical_crossentropy',
metrics=['accuracy']
)
history = model.fit(
train_generator,
steps_per_epoch = 25,
epochs = 25,
validation_data = validation_generator,
validation_steps = 25,
verbose = 1
)
plot_loss(history)
我也用
import logging
logging.getLogger("tensorflow").setLevel(logging.ERROR)
请指导我。
尝试将 steps_per_epoch = 25
和 steps_per_epoch = 25
替换为 batch_size = 25
。
我已经卸载了 Keras 和 Tensorflow,并使用
安装了它们 pip install tensorflow == 2.6
pip install keras == 2.6
但即使在之后,我仍然有一件奇怪的事,它只有 5 个 epoch 运行ning:
我无法追踪这种情况是何时发生的,但它曾经 运行 所有时期。 这是我的代码:
train_datagen = ImageDataGenerator(rescale = 1.0/255.)
test_datagen = ImageDataGenerator(rescale = 1.0/255.)
train_generator = tf.keras.utils.image_dataset_from_directory(base_dir,
batch_size=20,
label_mode='categorical',
validation_split = 0.2,
subset='training',
seed=123,
image_size=(200, 200))
validation_generator = tf.keras.utils.image_dataset_from_directory(base_dir,
batch_size=20,
label_mode='categorical',
validation_split = 0.2,
subset='validation',
seed=123,
image_size=(200, 200))
model = Sequential([
Conv2D(32, (3, 3), activation='relu', input_shape=(200, 200, 3)),
MaxPooling2D((2, 2)),
Conv2D(64, (3, 3), activation='relu'),
MaxPooling2D((2, 2)),
Conv2D(128, (3, 3), activation='relu'),
tf.keras.layers.Dropout(0.2),
Flatten(),
Dense(256, activation='relu'),
Dense(4, activation='softmax')
])
model.compile(optimizer='Adam',
loss='categorical_crossentropy',
metrics=['accuracy']
)
history = model.fit(
train_generator,
steps_per_epoch = 25,
epochs = 25,
validation_data = validation_generator,
validation_steps = 25,
verbose = 1
)
plot_loss(history)
我也用
import logging
logging.getLogger("tensorflow").setLevel(logging.ERROR)
请指导我。
尝试将 steps_per_epoch = 25
和 steps_per_epoch = 25
替换为 batch_size = 25
。