Skip to content

FaNa-AI/CNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐾 Dog Breed Classifier using CNN (PyTorch)

This repository contains a convolutional neural network (CNN) implemented in PyTorch to classify images of different dog breeds. The model is trained on a custom image dataset using a handcrafted CNN architecture, including data preprocessing, training loop, evaluation, and result visualization.


πŸ“ Dataset

  • Path: archive_4dog
  • The dataset should follow the ImageFolder structure:
archive_4dog/
  β”œβ”€β”€ breed1/
  β”‚    β”œβ”€β”€ img1.jpg
  β”‚    β”œβ”€β”€ img2.jpg
  β”œβ”€β”€ breed2/
  β”‚    β”œβ”€β”€ img3.jpg
  β”‚    β”œβ”€β”€ ...
  • Only .jpg and .png files are supported.
  • Corrupted images are automatically detected and removed before training.

🧠 Model Overview

The network includes:

  • 5 convolutional layers (with increasing filters: 32 β†’ 512)
  • ReLU activations and MaxPooling
  • Fully connected classifier with dropout
  • Custom image size: 150Γ—150

πŸš€ How to Run

1. Install Requirements

pip install torch torchvision matplotlib Pillow

2. Confirm Dataset Structure

Make sure the images are sorted into subfolders by class name (breed).

3. Run the Training Script

python train_cnn.py

This will:

  • Train the model
  • Save model as pet_classifier_final.pth
  • Save training graphs as training_results.png

βš™οΈ Hyperparameters

Parameter Value
Batch Size 32
Image Size 150Γ—150
Epochs 30
Optimizer Adam
Learning Rate 0.0001
Loss Function CrossEntropy

πŸ“Š Output

After training completes, the script generates:

  • pet_classifier_final.pth: Final trained model weights
  • training_results.png: Training/validation loss and accuracy curves

Example output:

Epoch [30/30]
Train Loss: 0.1734 | Val Loss: 0.2156 | Accuracy: 93.87%

πŸ“ˆ Training Visualization


πŸ›  Features

  • Custom convolutional neural network (from scratch)
  • Real-time training statistics
  • Automatic removal of corrupted images
  • Random rotation, flip, resize, crop augmentation

About

CNN-based dog breed classifier in PyTorch with custom dataset and data augmentation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published