This project implements an image classification pipeline using PyTorch and a pre-trained VGG16 model. The code uses transfer learning to classify grayscale images into multiple classes, based on a custom dataset structured in folders.
The dataset should follow the format:
π dataset_root/ βββ π Training/ β βββ π Class1/ β βββ π Class2/ β βββ ... βββ π Testing/ βββ π Class1/ βββ π Class2/ βββ ...
Each class folder should contain the respective images.
βοΈ Requirements
Install the required libraries using:
pip install torch torchvision scikit-learn matplotlib seabornπ How to Run Set the dataset paths in the script:
train_folder_path = "path/to/Training" test_folder_path = "path/to/Testing"
Run the script:
python main.pyThe script will:
Preprocess the data (resize, convert to 3 channels, normalize)
Train a VGG16 model for 10 epochs
Save and reload the trained model
Predict on the test set
Display a confusion matrix
Print the classification report
Model Details Backbone: VGG16 (pre-trained on ImageNet)
Modification: Final classifier layer adapted to number of classes
Input: Grayscale images resized to 224x224 and converted to 3-channel
Loss Function: CrossEntropyLoss
Optimizer: Adam
Output Loss per epoch
Confusion matrix (displayed using Seaborn)
Classification report (precision, recall, F1-score for each class)
β¨ Author Shruthikha Suresh Feel free to reach out for collaboration or questions!