'Keras - ImageDataGenerator incorrect split
I have tried split the data to train and validation part:
train_datagen = tf.keras.preprocessing.image.ImageDataGenerator(validation_split=0.1)
train_ds = train_datagen.flow_from_dataframe(train_labels, directory = data_path, x_col = 'image_name', y_col = 'class_id',target_size=(img_height, img_width), batch_size=batch_size, shuffle=True, subset="training")
val_ds = train_datagen.flow_from_dataframe(train_labels, directory = data_path, x_col = 'image_name', y_col = 'class_id',target_size=(img_height, img_width), batch_size=batch_size, shuffle=True, subset="validation")
but after start training I have overfitted validation after 5 epoch:
9/9 [==============================] - 30s 2s/step - loss: 0.9201 - acc: 0.5660 - val_loss: 0.1932 - val_acc: 0.9766
Epoch 2/40
9/9 [==============================] - 14s 2s/step - loss: 0.5094 - acc: 0.7786 - val_loss: 0.0882 - val_acc: 0.9844
Epoch 3/40
9/9 [==============================] - 14s 2s/step - loss: 0.3968 - acc: 0.8455 - val_loss: 0.0587 - val_acc: 0.9844
Epoch 4/40
9/9 [==============================] - 14s 2s/step - loss: 0.3262 - acc: 0.8733 - val_loss: 0.0408 - val_acc: 0.9844
Epoch 5/40
9/9 [==============================] - 14s 2s/step - loss: 0.3076 - acc: 0.8802 - val_loss: 0.0351 - val_acc: 0.9922
Because in validation part fall images belong with one class. What I can do?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
