I am training a model using Keras python library to recognize images of drawings that belong to two artists. Here is a screenshot of the flactuations I am seeing:
587/587 ━━━━━━━━━━━━━━━━━━━━ 906s 2s/step - accuracy: 0.5640 - loss: 0.7947 - val_accuracy: 0.4535 - val_loss: 2.7776 Epoch 2/100 587/587 ━━━━━━━━━━━━━━━━━━━━ 72s 120ms/step - accuracy: 0.6875 - loss: 0.6460 - val_accuracy: 0.4521 - val_loss: 2.3714 Epoch 3/100 587/587 ━━━━━━━━━━━━━━━━━━━━ 886s 2s/step - accuracy: 0.6059 - loss: 0.6735 - val_accuracy: 0.4670 - val_loss: 1.0623 Epoch 4/100 587/587 ━━━━━━━━━━━━━━━━━━━━ 72s 120ms/step - accuracy: 0.6562 - loss: 0.5518 - val_accuracy: 0.6021 - val_loss: 0.6561 Epoch 5/100 587/587 ━━━━━━━━━━━━━━━━━━━━ 874s 1s/step - accuracy: 0.6801 - loss: 0.5918 - val_accuracy: 0.5806 - val_loss: 0.7847 Epoch 6/100 587/587 ━━━━━━━━━━━━━━━━━━━━ 72s 120ms/step - accuracy: 0.5938 - loss: 0.6360 - val_accuracy: 0.5635 - val_loss: 1.1081 Epoch 7/100 587/587 ━━━━━━━━━━━━━━━━━━━━ 879s 1s/step - accuracy: 0.7032 - loss: 0.5737 - val_accuracy: 0.7170 - val_loss: 0.5536 Epoch 8/100 587/587 ━━━━━━━━━━━━━━━━━━━━ 71s 119ms/step - accuracy: 0.6562 - loss: 0.5647 - val_accuracy: 0.5729 - val_loss: 1.0483 Epoch 9/100 587/587 ━━━━━━━━━━━━━━━━━━━━ 887s 2s/step - accuracy: 0.7040 - loss: 0.5656 - val_accuracy: 0.5951 - val_loss: 1.3292
Why does one epoch take 900s but the next epoch only 70s? Does anyone know why this is happening and if that is considered normal behaviour?
Adding the code for more details:
STEP1: augmentation
image_gen = ImageDataGenerator(rotation_range=30, width_shift_range=0.1, height_shift_range=0.1, rescale=1/255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, fill_mode='nearest')
STEP2: model architecture
model = tf.keras.models.Sequential([
layers.Conv2D(32, (3, 3), activation='relu', input_shape=(300, 300, 3)),
layers.MaxPooling2D(2, 2),
layers.Conv2D(64, (3, 3), activation='relu', input_shape=(300, 300, 3)),
layers.MaxPooling2D(2, 2),
layers.Conv2D(64, (3, 3), activation='relu', input_shape=(300, 300, 3)),
layers.MaxPooling2D(2, 2),
layers.Conv2D(64, (3, 3), activation='relu', input_shape=(300, 300, 3)),
layers.MaxPooling2D(2, 2),
layers.Flatten(),
layers.Dense(512, activation='relu'),
layers.BatchNormalization(),
layers.Dense(512, activation='relu'),
layers.Dropout(0.1),
layers.BatchNormalization(),
layers.Dense(512, activation='relu'),
layers.Dropout(0.2),
layers.BatchNormalization(),
layers.Dense(1, activation='sigmoid') ])
model.summary()
model.compile(
loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
train_datagen = image_gen.flow_from_directory('data2/train', target_size=(300, 300), batch_size=32, class_mode='binary')
test_datagen = image_gen.flow_from_directory('data2/test', target_size=(300, 300), batch_size=32, class_mode='binary')
train_datagen.class_indices
history = model.fit(train_datagen, epochs=100, steps_per_epoch=18814//32, validation_data=test_datagen, validation_steps=2911//32)
STEP3: saving the model
model.save('my_model_11.keras')