This is a simple image classification project that uses a Convolutional Neural Network (CNN) to classify images from the CIFAR-10 dataset into one of 10 categories.
The CIFAR-10 dataset contains 60,000 32x32 color images categorized into 10 different classes:
- Airplane
- Automobile
- Bird
- Cat
- Deer
- Dog
- Frog
- Horse
- Ship
- Truck
This project trains a CNN model using TensorFlow/Keras to recognize these categories and evaluate its performance.
- Loads and preprocesses the CIFAR-10 dataset.
- Builds and trains a Convolutional Neural Network (CNN).
- Visualizes training and validation accuracy.
- Tests the model on unseen images.
- Predicts the category of any uploaded image.
- Python 3.7+
- TensorFlow/Keras: For building and training the CNN.
- Matplotlib: For visualizing performance.
- Google Colab: For running the project in a cloud environment.
- Open Google Colab at colab.research.google.com.
- Create a new notebook and copy-paste the project code.
- Install TensorFlow if needed:
!pip install tensorflow
- Run each code cell in sequence.
-
Data Loading:
- The CIFAR-10 dataset is loaded using TensorFlow/Keras.
- Images are normalized to a range of
[0, 1]
.
-
Model Building:
- A Convolutional Neural Network (CNN) is created with 3 convolutional layers, followed by dense layers.
-
Training:
- The model is trained on 50,000 images and validated on 10,000 images over 10 epochs.
-
Evaluation:
- The trained model's accuracy is evaluated on test data.
- A graph of training vs. validation accuracy is plotted.
-
Prediction:
- The model predicts the class of new or unseen images.
- Load an image for prediction (either from the test set or an external image).
- Use the trained model to predict its category.
- Output the category name (e.g., "Cat" or "Airplane").
Example code to predict a class:
# Class labels
class_labels = ['Airplane', 'Automobile', 'Bird', 'Cat', 'Deer', 'Dog', 'Frog', 'Horse', 'Ship', 'Truck']
# Predict the class
predicted_class = np.argmax(prediction)
print(f"Predicted Class: {class_labels[predicted_class]}")
- The model achieves ~70-80% accuracy on test data.
- It can correctly classify unseen images into one of the 10 categories.
- Add data augmentation to improve generalization.
- Use a more complex architecture for higher accuracy.
- Deploy the model using a simple web interface (e.g., Streamlit or Flask).
This project is open-source and free to use under the MIT License.
Feel free to modify and enhance the project as per your requirements! 😊