Home > OS >  Why does Keras run only 5 epochs out of 25?
Why does Keras run only 5 epochs out of 25?

Time:06-02

I have uninstalled Keras and Tensorflow and installed them both using

 pip install tensorflow == 2.6


 pip install keras == 2.6

But even after, I still have this strange thing that it's only 5 epochs that are running:

enter image description here

I cannot track when this situation occurred, but it used to run all of the epochs. Here is my code:

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)

I also use

import logging
logging.getLogger("tensorflow").setLevel(logging.ERROR)

Please direct me.

CodePudding user response:

Try replacing the steps_per_epoch = 25 and the steps_per_epoch = 25 with just batch_size = 25.

  • Related