This repository contains Python scripts for experimenting with image classification using both deep learning (ResNet) and traditional machine learning (PCA + k-NN) techniques. The code includes implementations for training a ResNet model on a custom dataset, applying PCA for dimensionality reduction followed by k-NN classification, and visualizing model performance with tools like Grad-CAM.
The dataset used in these scripts is assumed to be an image folder structure (e.g., ./data/train, ./data/valid, ./data/test) with subdirectories for each class, such as a butterfly species dataset. Adjust the paths and parameters as needed for your specific use case.
- Deep Learning: Trains a ResNet model with residual blocks for image classification.
- Traditional ML: Implements PCA for dimensionality reduction and k-NN for classification.
- Visualization: Includes loss/accuracy plots, confusion matrices, and Grad-CAM heatmaps for interpretability.
- Data Preprocessing: Applies image transformations like resizing, normalization, and augmentation.
- Python 3.8+
- Libraries:
torch(PyTorch)torchvisionnumpymatplotlibscikit-learntqdmPillow(PIL)opencv-python(cv2)torchcam(for Grad-CAM visualization)
- Clone this repository:
git clone https://github.com/your-username/your-repo-name.git cd your-repo-name