This project demonstrates image classification using the CIFAR-10 dataset and a Convolutional Neural Network (CNN) built with TensorFlow and Keras. The CIFAR-10 dataset consists of 60,000 32x32 color images in 10 different classes, with 6,000 images per class.
main.py: The main script that loads the dataset, preprocesses the images, defines the CNN model, trains the model, and makes predictions.image_classification.model: The saved model after training.
- Python 3.x
- TensorFlow
- NumPy
- Matplotlib
You can install the required packages using pip:
pip install tensorflow numpy matplotlib-
Load and Preprocess Data: The CIFAR-10 dataset is loaded and the images are normalized by dividing by 255.
-
Define the Model: A CNN model is defined using Keras' Sequential API. The model consists of convolutional layers, max-pooling layers, and dense layers.
-
Train the Model: The model is compiled with the Adam optimizer and sparse categorical cross-entropy loss. It is then trained on the training data.
-
Save the Model: After training, the model is saved to a file.
-
Load the Model: The saved model is loaded from the file.
-
Make Predictions: The model is used to make predictions on a sample image from the training set.
To run the project, execute the main.py script:
python main.pyThe script will load the CIFAR-10 dataset, preprocess the images, load the pre-trained model, and make a prediction on a sample image. The predicted class will be displayed along with the image.
The model's performance can be evaluated using the test dataset. The accuracy and loss will be printed after evaluation.
The script includes commented-out code for visualizing the first 16 images in the training set along with their labels. Uncomment the code to see the images.
This project is licensed under the MIT License.