This project focuses on building a Convolutional Neural Network (CNN) to classify images of animals. The model is developed using PyTorch and leverages transfer learning techniques.
Computer Vision
The project utilizes the Animal Image Classification Dataset. Dataset Source: Kaggle: Animal Image Classification Dataset
- Image Preprocessing
- CNN Architecture with PyTorch
- Model Evaluation (Accuracy, Precision, Recall, F1-Score, and Confusion Matrix)
The following tasks were performed as part of this project:
- Load and preprocess the image dataset
- Design a 2-3 layer CNN (using a pre-trained ResNet-18 model)
- Train, validate, and test the model
- Visualize predictions using Matplotlib
The project is organized with the following directory structure:
-
Clone the Repository (if applicable):
git clone <your-repo-url> cd Animal_Image_Classifier
-
Install Libraries: Ensure you have all the required libraries by running:
pip install -r requirements.txt
(torch, numpy, torchvision, matplotlib, time, os, PIL, tempfile, scikitlearn, seaborn, pandas)
-
Prepare the Dataset: Download the dataset from the Kaggle link provided above and place the
train
,val
, andtest
subdirectories into the1_data
folder as per the folder structure. -
Run the Jupyter Notebook: Open the
your_project_notebook.ipynb
(or similar name) located in the3_notebooks
directory using Jupyter Notebook or JupyterLab and execute the cells sequentially.The notebook will:
- Load and preprocess images.
- Initialize and train two models: a fine-tuned ResNet-18 model and a ResNet-18 feature extractor.
- Save the trained models in the
2_models
directory. - Visualize model predictions.
- Generate and save classification reports and confusion matrices in the
4_results
directory. - Display training and validation graphs (if plotting code is included to save them in
5_outputs/2. Graphs
).
The project evaluates the performance of both the fine-tuned CNN model (model_ft
) and the transfer learning feature extraction model (model_conv
) on the validation dataset.
The evaluation includes:
- Loss and Accuracy per Epoch: Printed during the training process for both training and validation phases.
- Classification Report: Provides precision, recall, f1-score, and support for each class.
- Confusion Matrix: Visualizes the number of correct and incorrect predictions for each class.
These evaluation reports (_classification_report.txt
and _confusion_matrix.png
) are saved in the 4_results
directory for both models, allowing for direct comparison of their classification abilities.