text_plain_output_1.png
from keras.preprocessing.image import ImageDataGenerator

import keras

train_gen = ImageDataGenerator(rotation_range=10, rescale=1.0 / 255, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False, zoom_range=0.1, shear_range=0.1, brightness_range=[0.8, 1.2], fill_mode='nearest', validation_split=0.2)
train_data = train_gen.flow_from_directory('/kaggle/input/5-flower-types-classification-dataset/flower_images', target_size=(224, 224), batch_size=32, class_mode='categorical', shuffle=True, subset='training')
test_data = train_gen.flow_from_directory('/kaggle/input/5-flower-types-classification-dataset/flower_images', target_size=(224, 224), batch_size=1, shuffle=False, subset='validation')

cnn = keras.models.Sequential()
cnn.add(keras.layers.Conv2D(filters=32, kernel_size=3, padding='valid', activation='relu', input_shape=(224, 224, 3)))
cnn.add(keras.layers.MaxPool2D(pool_size=2, strides=2))
cnn.add(keras.layers.Flatten())
cnn.add(keras.layers.Dense(45, activation='relu'))
cnn.add(keras.layers.Dense(15, activation='relu'))
cnn.add(keras.layers.Dropout(rate=0.1, seed=100))
cnn.add(keras.layers.Dense(units=5, activation='sigmoid'))

cnn.summary()

cnn.compile(optimizer='adam', metrics=['accuracy'], loss='categorical_crossentropy')

cnn.fit(train_data, epochs=20, validation_data=test_data, shuffle=True, callbacks=keras.callbacks.EarlyStopping(monitor='val_loss', patience=10))