Fine-grained animal recognition project for the CVDL SEP challenge.
The current submission is built as a two-stage pipeline:
Final_Project/detector.pyruns a YOLOv6 detector and selects the largest cat or dog in the image.Final_Project/animalClassifier.pyruns an EfficientNetV2-S breed classifier on the cropped animal.AnimalRecognitionChallenge/inference.pywraps both stages for the official evaluation interface and returns a class index in0..19or-1for reject.
The challenge label order is fixed in AnimalRecognitionChallenge/inference.py:
0..9= cat breeds10..19= dog breeds-1= no target animal / reject
- Python
- PyTorch and TorchVision
- YOLOv6 via
torch.hub - EfficientNetV2-S for breed classification
- OpenCV, NumPy, Pillow
- pandas, scikit-learn, tqdm
- Grad-CAM for explainable AI visualizations
- Slurm batch scripts for training on the LMU cluster
CVDL26-drop-table-catdogs/
|-- AnimalRecognitionChallenge/
| `-- inference.py # Official evaluation entry point
|-- Final_Project/
| |-- detector.py # YOLOv6 crop selection
| |-- animalClassifier.py # EfficientNetV2-S breed classifier
| |-- train.py # Current crop-based training pipeline
| |-- traineffnet.py # Alternate ImageFolder training baseline
| |-- evaluate.py # Checkpoint inspection helper
| |-- compare_classifier.py # ResNet18 diagnostic comparator
| |-- visualize_cam.py # Grad-CAM heatmap generation
| |-- xAI_GradCam.py # Legacy / experimental XAI helper
| |-- sorting_folder_images.py # Merge class folders into flat images/
| `-- download_model_detector.py # Download YOLOv6s weights
|-- Training_Material/
| |-- cat_api.py # TheCatAPI data collection helper
| |-- kagel_dataset.py # Kaggle cat-breed collection helper
| |-- kaggle_dog.py # Stanford dogs collection helper
| |-- oxford_loader.py # Oxford-IIIT Pet collection helper
| |-- extended_dogs_loader.py # Stanford + local Dalmatian integration
| `-- jan_dalamtian.py # Local Dalmatian import helper
|-- notebooks/
| |-- 01_train_combined.ipynb
| `-- 02_train_species_split.ipynb
|-- Final_Report/ # Final report LaTeX project
|-- Preliminary_Report/ # Early report LaTeX project
|-- LaTeXAuthor Guidelines for CVDL SEP Report/
|-- run_training.sh # Slurm training launcher
|-- run_visualization_cam.sh # Batch Grad-CAM launcher
|-- requirements.txt
|-- yolov6s.pt # Detector weights
`-- README.md
AnimalRecognitionChallenge/inference.py is the submission-facing script.
input image
-> YOLOv6 detector
-> largest detected cat/dog crop
-> 224x224 resize
-> EfficientNetV2-S breed classifier
-> predicted breed index or -1
The detector and classifier are separated so the classifier sees a standardized crop instead of the full background.
The active training path is Final_Project/train.py.
- It builds a cropped-animal dataset from
images/labels.csv. - It caches detector crops to avoid repeated YOLOv6 calls.
- It supports optional augmentation flags:
--mirror--blur--cropmix
- It supports optional class reweighting with
--balance_weights. - It trains one classifier for cats and one classifier for dogs.
- It saves checkpoints as
cat_scratch_<exp>.pthanddog_scratch_<exp>.pth.
Final_Project/traineffnet.py is an earlier alternate experiment that trains a single 20-class classifier from an ImageFolder layout with weighted sampling and ImageNet initialization.
The helper scripts in Training_Material/ document how the dataset was assembled.
cat_api.pywas used for early TheCatAPI collection.kagel_dataset.py,kaggle_dog.py, andoxford_loader.pycover the main curated sources used later in the project.extended_dogs_loader.pyadds missing dog breeds and local Dalmatian images.jan_dalamtian.pyhandles the Dalmatian-only local import.
The report materials describe a project history that started with API-based collection, then moved toward larger curated sources and additional breed-specific patches to improve coverage. The current repository keeps the loaders and merge helpers used for that workflow.
- Create and activate a Python virtual environment.
- Install dependencies:
pip install -r requirements.txt- Make sure the data folder expected by the training scripts exists:
images/
|-- labels.csv
|-- 00000.jpg
|-- 00001.jpg
`-- ...
- If you want to use the folder-based helpers, also prepare a
classes/directory with one folder per breed.
The provided Slurm launcher is run_training.sh.
sbatch run_training.shNotes:
- The script is written for the LMU cluster and contains a hardcoded project path.
- The current array jobs sweep several learning-rate, epoch, and augmentation combinations.
- Adjust the working directory and virtual environment path if you run it elsewhere.
To run the training script directly:
python Final_Project/train.py --data_dir ./images --lr 1e-6 --epochs 100 --exp_name demo --balance_weightsAdd --mirror, --blur, or --cropmix as needed.
The challenge entry point is:
python AnimalRecognitionChallenge/inference.py --image-folder <path-to-test-images>Expected local files:
yolov6s.ptfor the detectorcat_scratch.pthanddog_scratch.pthfor the breed classifiers
If yolov6s.pt is missing, Final_Project/download_model_detector.py can download it from the official YOLOv6 release.
Final_Project/visualize_cam.py generates Grad-CAM heatmaps for a chosen image and checkpoint.
Example:
python Final_Project/visualize_cam.py --checkpoint <path-to-checkpoint> --image <image-path> --species catThe batch helper run_visualization_cam.sh repeatedly generates heatmaps for random images.
Final_Report/contains the LaTeX source for the final paper.Preliminary_Report/keeps the earlier report version.- The final scientific report should describe the full pipeline, the experiments, the XAI analysis, and the team contribution appendix.
- Remove or clearly quarantine legacy and debug code paths in the submission-facing scripts, especially any leftover comparison or placeholder branches.
- Keep only the final training and inference paths in the shipped archive, or label backup scripts as archival so they are not mistaken for the primary workflow.
- Verify the final submission still runs from a clean checkout with the documented weight files and no hidden local-path assumptions.
- Keep a source URL list for any images collected from the internet, and record the exact preprocessing commands used to build
images/.