Path: blob/master/Applied Generative AI with GANS/9 Capstone Project CNN - Participants Guide.ipynb
4909 views
Objective
Build, train, and evaluate a CNN using Keras on CIFAR-10 To learn a model that correctly assigns each input image to exactly one of 10 predefined object classes.
CIFAR-10 (Canadian Institute For Advanced Research) is a benchmark image classification dataset widely used to evaluate Convolutional Neural Networks (CNNs) and other computer vision models.
It is designed to be:
Small enough to train quickly
Complex enough to demonstrate real-world image challenges
Data Composition
| Attribute | Description |
|---|---|
| Total images | 60,000 |
| Training images | 50,000 |
| Test images | 10,000 |
| Image size | 32 × 32 pixels |
| Color channels | 3 (RGB) |
| Classes | 10 |
| Images per class | 6,000 (5,000 train + 1,000 test) |
The dataset contains the following 10 mutually exclusive object categories:
Airplane, Automobile, Bird, Cat, Deer, Dog, Frog, Horse, Ship,Truck
This mix intentionally includes:
Animals (biological objects)
Vehicles (man-made objects)
Step 1: Load Dataset
Downloading data from https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
170498071/170498071 ━━━━━━━━━━━━━━━━━━━━ 25s 0us/step
(50000, 32, 32, 3) (50000, 1)
Step 2: Visualize Sample Images (Human View)
Before training any model, it is critical to visually inspect the data. This helps confirm:
Images are correctly loaded
Labels match what humans perceive
Data quality is acceptable
Step 3: Data Preprocessing
Step 4: CNN Model Design
Step 5: Compile and Train
Epoch 1/10
704/704 ━━━━━━━━━━━━━━━━━━━━ 9s 11ms/step - accuracy: 0.4713 - loss: 1.4763 - val_accuracy: 0.5736 - val_loss: 1.1962
Epoch 2/10
704/704 ━━━━━━━━━━━━━━━━━━━━ 8s 11ms/step - accuracy: 0.6038 - loss: 1.1313 - val_accuracy: 0.6352 - val_loss: 1.0437
Epoch 3/10
704/704 ━━━━━━━━━━━━━━━━━━━━ 8s 12ms/step - accuracy: 0.6544 - loss: 0.9925 - val_accuracy: 0.6668 - val_loss: 0.9771
Epoch 4/10
704/704 ━━━━━━━━━━━━━━━━━━━━ 8s 11ms/step - accuracy: 0.6880 - loss: 0.8975 - val_accuracy: 0.6932 - val_loss: 0.9041
Epoch 5/10
704/704 ━━━━━━━━━━━━━━━━━━━━ 8s 11ms/step - accuracy: 0.7138 - loss: 0.8240 - val_accuracy: 0.6942 - val_loss: 0.8921
Epoch 6/10
704/704 ━━━━━━━━━━━━━━━━━━━━ 8s 11ms/step - accuracy: 0.7383 - loss: 0.7479 - val_accuracy: 0.6978 - val_loss: 0.8793
Epoch 7/10
704/704 ━━━━━━━━━━━━━━━━━━━━ 8s 11ms/step - accuracy: 0.7616 - loss: 0.6823 - val_accuracy: 0.7048 - val_loss: 0.8695
Epoch 8/10
704/704 ━━━━━━━━━━━━━━━━━━━━ 8s 11ms/step - accuracy: 0.7854 - loss: 0.6196 - val_accuracy: 0.7034 - val_loss: 0.8874
Epoch 9/10
704/704 ━━━━━━━━━━━━━━━━━━━━ 8s 11ms/step - accuracy: 0.8022 - loss: 0.5649 - val_accuracy: 0.7094 - val_loss: 0.9191
Epoch 10/10
704/704 ━━━━━━━━━━━━━━━━━━━━ 8s 11ms/step - accuracy: 0.8258 - loss: 0.5070 - val_accuracy: 0.7112 - val_loss: 0.8951
Step 6: Evaluation
313/313 ━━━━━━━━━━━━━━━━━━━━ 1s 3ms/step - accuracy: 0.7027 - loss: 0.9355
Test Accuracy: 0.7027000188827515
Reflection
Why is visual inspection of data important before training a CNN?