A Python application that uses pre-trained CNN models to classify pet images and determine if they are dogs or not.
Name: Ritik Kumar
Date Created: October 3, 2025
This project classifies pet images using pre-trained CNN models (ResNet, AlexNet, or VGG) and compares the results against true labels. It also determines whether images correctly classify dogs and dog breeds.
- Supports multiple CNN architectures: ResNet, AlexNet, VGG
- Automatic pet label extraction from filenames
- Dog breed classification
- Statistical analysis of classification results
- Detailed error reporting
- Python 3.6 or higher
- PyTorch
- torchvision
- Pillow (PIL)
- Clone this repository
- Install dependencies:
pip install -r requirements.txtBasic usage with default settings (VGG model, pet_images folder):
python check_images.pySpecify a different model:
python check_images.py --arch resnetSpecify a different image directory:
python check_images.py --dir /path/to/images/Specify a different dog names file:
python check_images.py --dogfile custom_dognames.txt--dir: Path to folder of pet images (default: 'pet_images/')--arch: CNN model architecture - choices: resnet, alexnet, vgg (default: 'vgg')--dogfile: Text file containing valid dog names (default: 'dognames.txt')
.
├── check_images.py # Main script
├── get_input_args.py # Command line argument parsing
├── get_pet_labels.py # Extract labels from filenames
├── classify_images.py # Classify images using CNN
├── adjust_results4_isadog.py # Determine if classification is a dog
├── calculates_results_stats.py # Calculate statistics
├── print_results.py # Print results
├── classifier.py # CNN classifier wrapper
├── print_functions_for_lab_checks.py # Helper functions for checking
├── dognames.txt # Valid dog breed names
├── imagenet1000_clsid_to_human.txt # ImageNet class labels
├── requirements.txt # Python dependencies
└── pet_images/ # Folder containing pet images
Image files should follow this naming pattern:
Breed_name_number.jpg
Example: Golden_retriever_05223.jpg
The script extracts the breed name by:
- Converting filename to lowercase
- Splitting by underscores
- Keeping only alphabetic words
- Joining words with spaces
The script provides:
- Number of images processed
- Number of dog images
- Number of non-dog images
- Percentage of correct matches
- Percentage of correct dog classifications
- Percentage of correct breed classifications
- Percentage of correct non-dog classifications
- Lists of incorrect classifications (if any)
The application includes comprehensive error handling for:
- Missing files and directories
- Invalid model names
- Missing dependencies
- File read/write errors
- Classification failures
- The first run may take longer as it downloads pre-trained model weights
- Ensure all image files are valid and readable
- The dognames.txt file should contain one dog breed per line
- Hidden files (starting with '.') are automatically skipped
PyTorch not found:
pip install torch torchvisionPIL/Pillow errors:
pip install --upgrade PillowModel download issues: Ensure you have a stable internet connection for the first run to download model weights.
See LICENSE file for details.