import tensorflow as tf from tensorflow.keras.preprocessing.image import ImageDataGenerator from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Flatten, Dense import matplotlib.pyplot as plt # Parameters IMG_SIZE = 64 BATCH_SIZE = 32 NUM_CLASSES = 4 EPOCHS = 20 # Data generators train_datagen = ImageDataGenerator(rescale=1./255) test_datagen = ImageDataGenerator(rescale=1./255) train_data = train_datagen.flow_from_directory( "brain_tumor_classification/Training", target_size=(IMG_SIZE, IMG_SIZE), batch_size=BATCH_SIZE, class_mode="categorical" ) test_data = test_datagen.flow_from_directory( "brain_tumor_classification/Testing", target_size=(IMG_SIZE, IMG_SIZE), batch_size=BATCH_SIZE, class_mode="categorical" ) # Model model = Sequential([ Flatten(input_shape=(IMG_SIZE, IMG_SIZE, 3)), Dense(512, activation='relu'), Dense(256, activation='relu'), Dense(216, activation='relu'), Dense(NUM_CLASSES, activation='softmax') ]) # Compile model.compile( optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'] ) # Train history = model.fit( train_data, validation_data=test_data, epochs=EPOCHS ) # Plot results plt.figure(figsize=(12, 4)) # Accuracy plt.subplot(1, 2, 1) plt.plot(history.history['accuracy'], label='Train') plt.plot(history.history['val_accuracy'], label='Validation') plt.title('Accuracy') plt.legend() # Loss plt.subplot(1, 2, 2) plt.plot(history.history['loss'], label='Train') plt.plot(history.history['val_loss'], label='Validation') plt.title('Loss') plt.legend() plt.show()