Final project for the Introduction to Computer Vision course.
The program receives an image and classifies it as one of the ten animals in the Animals-10 dataset. The project compares two methods studied during the course:
- HOG features with a linear SVM;
- VGG16 transfer learning with limited fine-tuning.
Both methods use the same training, validation and test images.
The dataset is Animals-10. It contains images of butterfly, cat, chicken, cow, dog, elephant, horse, sheep, spider and squirrel. Kaggle reports the GPL 2 license and states that the images were collected from Google Images.
The local copy contains 26,179 readable images:
| Class | Images | Class | Images |
|---|---|---|---|
| Butterfly | 2,112 | Cat | 1,668 |
| Chicken | 3,098 | Cow | 1,866 |
| Dog | 4,863 | Elephant | 1,446 |
| Horse | 2,623 | Sheep | 1,820 |
| Spider | 4,821 | Squirrel | 1,862 |
The dataset is not included in the repository. After downloading and
extracting it, the original raw-img folder must be placed here:
data/raw/raw-img/
The project uses Python 3.12.
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txtThe images are checked with OpenCV and randomly divided with seed 42:
- 18,325 training images (70%);
- 3,926 validation images (15%);
- 3,928 test images (15%).
The split is not stratified. The test set was kept separate until the final evaluation.
# Check the original images
python -m src.data
# Create the three folders
python -m src.data splitEach image is resized to 64x128 pixels and converted to grayscale. HOG extracts edge and shape information, and an OpenCV linear SVM performs the classification.
python -m src.hog_svmImages are converted to RGB, resized to 150x150 pixels and normalized between 0 and 1. Data augmentation is applied only to the training images.
VGG16 is loaded with ImageNet weights and a new classification head:
Flatten -> Dense(256, ReLU) -> Dense(10, Softmax)
First, the VGG16 base remains frozen while the new head is trained for five
epochs. Then the last four VGG16 layers are fine-tuned for another five epochs
with learning rate 1e-5.
python -m src.cnn
python -m src.fine_tuningThe training was run on Google Colab using these notebooks:
The fine-tuned VGG16 was selected using validation results. After fixing both models, they were evaluated once on the same test set.
| Model | Accuracy | Macro precision | Macro recall | Macro F1 | Weighted F1 |
|---|---|---|---|---|---|
| HOG + linear SVM | 0.3778 | 0.3575 | 0.3552 | 0.3495 | 0.3753 |
| Fine-tuned VGG16 | 0.8691 | 0.8564 | 0.8593 | 0.8551 | 0.8692 |
The complete per-class metrics and training curves are available in the
results folder.
To reproduce the final evaluation:
python -m src.final_evaluationError analysis was performed on validation images so that the test set did not become another development set.
- HOG-SVM validation errors: 2,414;
- VGG16 validation errors: 511;
- errors shared by both models: 388.
HOG is often affected by unusual poses, tight crops and complex backgrounds. VGG16 makes fewer errors but can still fail with multiple animals, visually similar classes, noisy images or ambiguous labels.
The analysis can be reproduced with:
python -m src.failure_analysisAnimals-10 is unbalanced and contains images collected online. Breeds, poses, lighting and backgrounds are therefore not represented equally. Some images are drawings, statues, contain multiple animals or may have an incorrect label.
The application always selects one of the ten known classes, even when the input contains another species or no animal. The Softmax score is not a guarantee that the prediction is correct. The intended use is academic, educational or simple image cataloguing, not universal zoological identification.
The dataset is excluded from GitHub. Copyright of individual online images and the possible presence of people in photographs must also be considered.
python main.py "/path/to/image.jpg"Example output:
Model: VGG16 fine-tuned
Predicted class: CAT
Softmax score: 0.9821
main.py final prediction command
config.py paths and basic settings
src/data.py dataset check and split
src/preprocessing.py image preprocessing
src/hog_svm.py HOG-SVM training
src/cnn.py frozen VGG16 training
src/fine_tuning.py VGG16 fine-tuning
src/final_evaluation.py final test evaluation
src/failure_analysis.py validation error analysis
src/predict.py prediction of one image
results/ saved metrics and figures


