Downloads · 30 days
0
s-a-n-08/GAN
GAN is a machine learning model from s-a-n-08. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
A complete implementation of a Convolutional Neural Network (CNN) for image classification using PyTorch. This project includes data loading, model training, evaluation, and inference capabilities with comprehensive m…
Downloads · 30 days
0
Access
Public
Updated Feb 7, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.py63 KB · 87%
From the Hugging Face model README
A complete implementation of a Convolutional Neural Network (CNN) for image classification using PyTorch. This project includes data loading, model training, evaluation, and inference capabilities with comprehensive metrics tracking and visualization.
CNN1/
├── config.py # Configuration and hyperparameters
├── train.py # Main training script
├── evaluate.py # Model evaluation script
├── inference.py # Inference on new images
├── requirements.txt # Python dependencies
├── data/ # Data loading and preprocessing
│ ├── __init__.py
│ ├── dataset.py # Dataset loaders
│ └── transforms.py # Data transformations
├── models/ # Model architectures
│ ├── __init__.py
│ ├── cnn.py # CNN model definition
│ └── utils.py # Model utilities
├── utils/ # Training and evaluation utilities
│ ├── __init__.py
│ ├── trainer.py # Trainer class
│ ├── metrics.py # Metrics tracking
│ └── visualization.py # Visualization functions
├── checkpoints/ # Saved model checkpoints
├── logs/ # Training logs
└── results/ # Evaluation results and plots
cd c:\CNN\CNN1
pip install -r requirements.txt
The project uses the CIFAR-10 dataset, which consists of:
The dataset will be automatically downloaded on first run.
Train the model with default settings:
python train.py
Train with custom parameters:
python train.py --epochs 50 --batch-size 64 --lr 0.0001
Training outputs:
checkpoints/results/training_history.jsonresults/training_history.pngEvaluate the trained model on the test set:
python evaluate.py
Evaluate a specific checkpoint:
python evaluate.py --checkpoint checkpoints/best_model.pth
Evaluation outputs:
results/evaluation_metrics.jsonresults/confusion_matrix.pngresults/per_class_metrics.pngresults/sample_predictions.pngMake predictions on a new image:
python inference.py --image path/to/image.jpg --visualize
With custom parameters:
python inference.py --image path/to/image.jpg --checkpoint checkpoints/best_model.pth --top-k 3 --visualize --output results/prediction.png
All hyperparameters and settings can be modified in config.py:
conv_channels: [32, 64, 128, 256] - Channels for each conv blockfc_hidden: 512 - Hidden units in FC layerdropout_rate: 0.5 - Dropout probabilityNUM_EPOCHS: 100BATCH_SIZE: 128LEARNING_RATE: 0.001OPTIMIZER: 'Adam' (options: Adam, SGD, AdamW)SCHEDULER: 'ReduceLROnPlateau'EARLY_STOPPING_PATIENCE: 15 epochsMIN_DELTA: 0.001The CNN model consists of:
Convolutional Blocks (4 blocks):
Fully Connected Layers:
Regularization:
With default configuration, you can expect:
To use a custom dataset, modify data/dataset.py:
def get_custom_loaders():
# Implement your custom dataset loading
pass
Modify the model architecture in models/cnn.py:
model = CNN(
num_classes=10,
conv_channels=[64, 128, 256, 512], # Deeper network
fc_hidden=1024,
dropout_rate=0.3
)
The trainer supports:
During training and evaluation:
Reduce batch size in config.py:
BATCH_SIZE = 64 # or 32
NUM_WORKERS if CPU is bottleneckFeel free to:
This project is open source and available for educational purposes.
Happy Training! 🚀