image_output_1.png
from keras.preprocessing.image import ImageDataGenerator

from sklearn.model_selection import train_test_split, StratifiedKFold, KFold, cross_val_score, GridSearchCV

import pandas as pd

learning_rate = 0.001
weight_decay = 0.0001
batch_size = 256
num_epochs = 1000
image_size = 72
patch_size = 6
num_patches = (image_size // patch_size) ** 2
projection_dim = 64
num_heads = 4
transformer_units = [projection_dim * 2, projection_dim]
transformer_layers = 8
mlp_head_units = [2048, 1024]

input_shape = (72, 72, 3)
num_classes = 7
image_dir = '/kaggle/input/balanced-datasets/Smote_dataset'
df = pd.read_csv('/kaggle/input/balanced-datasets/Smote_dataset/labels.csv')
train_val_df, test_df = train_test_split(df, stratify=df['label'], test_size=0.1, random_state=42)
train_df, validation_df = train_test_split(train_val_df, stratify=train_val_df['label'], test_size=0.2, random_state=42)
augmented_datagen = ImageDataGenerator(rescale=1.0 / 255, rotation_range=40, width_shift_range=0.2, height_shift_range=0.2, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, fill_mode='nearest')
datagen = ImageDataGenerator(rescale=1.0 / 255)
train_generator = augmented_datagen.flow_from_dataframe(train_df, directory=image_dir, batch_size=batch_size, target_size=(image_size, image_size), x_col='filename', y_col='label', class_mode='categorical', shuffle=True)
val_generator = datagen.flow_from_dataframe(validation_df, directory=image_dir, batch_size=batch_size, target_size=(image_size, image_size), x_col='filename', y_col='label', class_mode='categorical', shuffle=True)
test_generator = datagen.flow_from_dataframe(test_df, directory=image_dir, x_col='filename', y_col='label', target_size=(image_size, image_size), batch_size=20, class_mode='categorical')