 print("in some cases there will be some warning in the beginning dont worry about that until execution is completed")
 
 import tensorflow as tf
 from tensorflow.keras import datasets, layers, models
 from tensorflow.keras.callbacks import EarlyStopping
 import matplotlib.pyplot as plt
 from tensorflow.keras.layers import MaxPooling2D,BatchNormalization,Conv2D,Flatten,Dropout
 (train_images, train_labels), (test_images, test_labels) =datasets.cifar10.load_data()
 train_images, test_images = train_images / 255.0, test_images / 255.0
 train_labels = tf.keras.utils.to_categorical(train_labels, 10)
 test_labels = tf.keras.utils.to_categorical(test_labels, 10)

 model = models.Sequential([
    Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 
3)),
    BatchNormalization(),
    MaxPooling2D((2, 2)),
    
    Conv2D(64, (3, 3), activation='relu'),
    BatchNormalization(),
    MaxPooling2D((2, 2)),
    
    Conv2D(128, (3, 3), activation='relu'),
    BatchNormalization(),
    layers.MaxPooling2D((2, 2)),
    
    Flatten(),
    Dense(128, activation='relu'),
    Dropout(0.5),
    Dense(10, activation='softmax')
 ])
 model.compile(optimizer='adam',
              loss='categorical_crossentropy',
              metrics=['accuracy'])
 early_stopping = EarlyStopping(monitor='val_loss', patience=5, 
restore_best_weights=True)
 history = model.fit(train_images, train_labels, epochs=2, 
                    validation_data=(test_images, test_labels),
                    callbacks=[early_stopping])
 test_loss, test_acc = model.evaluate(test_images, test_labels, 
verbose=2)

 print(f'Test accuracy: {test_acc * 100:.2f}%')

 plt.figure(figsize=(12, 6))
 plt.subplot(1, 2, 1)
 plt.plot(history.history['accuracy'], label='Train Accuracy')
 plt.plot(history.history['val_accuracy'], label='Validation Accuracy')
 plt.title('Training and Validation Accuracy')
 plt.xlabel('Epochs')
 plt.ylabel('Accuracy')
 plt.legend()
 plt.subplot(1, 2, 2)
 plt.plot(history.history['loss'], label='Train Loss')
 plt.plot(history.history['val_loss'], label='Validation Loss')
 plt.title('Training and Validation Loss')
 plt.xlabel('Epochs')
 plt.ylabel('Loss')
 plt.legend()
 plt.tight_layout()
 plt.show()
