# Step 1: Train ResNet18 on CIFAR-10
python train.py --dataset cifar10 --model resnet18 --epochs 20 --batch-size 128 --lr 0.001
# Step 2: Test the model interactively
python tests/test_model.py --dataset cifar10 --mode interactive
# In interactive mode:
>>> random 20 # Test 20 random images
>>> accuracy # Calculate full accuracy
>>> sample 100 # Test specific image
>>> exitExpected Results:
- Training time: ~15-20 minutes (RTX 3060 Ti)
- Accuracy: ~80-85% after 20 epochs
- Model saved:
./models/best_model.pt
# Fast training for testing the framework
python train.py --dataset synthetic --num-samples 500 --epochs 3 --batch-size 32
# Quick random testing
python tests/test_model.py --dataset synthetic --mode random --samples 10Use Case: Testing your setup, debugging, quick experiments
# Train on MNIST
python train.py --dataset mnist --model simple --epochs 10 --batch-size 64
# Test accuracy
python tests/test_model.py --dataset mnist --mode accuracyExpected Results:
- Training time: ~3-5 minutes
- Accuracy: ~98-99%
- Perfect for learning and demonstrations
# Train ResNet on Fashion-MNIST
python train.py --dataset fashion_mnist --model resnet18 --epochs 20 --batch-size 128
# Interactive testing
python tests/test_model.py --dataset fashion_mnist --mode interactive
>>> random 50
>>> accuracyClasses: T-shirt, Trouser, Pullover, Dress, Coat, Sandal, Shirt, Sneaker, Bag, Ankle boot
# Run evolutionary NAS
python examples/neural_architecture_search.pyWhat it does:
- Searches for optimal architecture
- Uses evolutionary algorithm
- Tests 15 architectures over 20 generations
- Outputs best architecture with parameters
Expected Output:
Best Architecture Found:
Fitness: 0.7234
Accuracy: 78.45%
Parameters: 1,234,567
FLOPs: 98,765,432
# examples/my_custom_training.py
import sys
sys.path.insert(0, '.')
import torch
import torch.nn as nn
from src.python.neuralforge import Trainer, Config
from src.python.neuralforge.data.real_datasets import get_dataset
from src.python.neuralforge.data.dataset import DataLoaderBuilder
from src.python.neuralforge.models.resnet import ResNet18
from src.python.neuralforge.optim.optimizers import AdamW
# Configuration
config = Config()
config.batch_size = 128
config.epochs = 50
config.learning_rate = 0.001
# Load CIFAR-10
train_dataset = get_dataset('cifar10', train=True, download=True)
val_dataset = get_dataset('cifar10', train=False, download=True)
# Data loaders
loader_builder = DataLoaderBuilder(config)
train_loader = loader_builder.build_train_loader(train_dataset)
val_loader = loader_builder.build_val_loader(val_dataset)
# Model
model = ResNet18(num_classes=10)
# Training
criterion = nn.CrossEntropyLoss()
optimizer = AdamW(model.parameters(), lr=config.learning_rate)
trainer = Trainer(model, train_loader, val_loader, optimizer, criterion, config)
trainer.train()
print(f"Best loss: {trainer.best_val_loss:.4f}")Run it:
python examples/my_custom_training.py# Train a model first
python train.py --dataset cifar10 --epochs 20
# Test with your own images
python tests/test_model.py --dataset cifar10 --mode interactive
# In interactive mode:
>>> image ./my_photos/cat.jpg
Custom Image: ./my_photos/cat.jpg
Predicted: cat
Confidence: 94.3%
Top-5 Predictions:
1. cat 94.3%
2. dog 3.2%
3. deer 1.5%
4. bird 0.7%
5. frog 0.3%Requirements:
- Image should contain objects similar to training classes
- Will be automatically resized to match model input
# Train on different datasets
python train.py --dataset mnist --model simple --epochs 10
mv ./models/best_model.pt ./models/mnist_best.pt
python train.py --dataset fashion_mnist --model resnet18 --epochs 20
mv ./models/best_model.pt ./models/fashion_best.pt
python train.py --dataset cifar10 --model resnet18 --epochs 30
mv ./models/best_model.pt ./models/cifar10_best.pt
# Test each
python tests/test_model.py --model ./models/mnist_best.pt --dataset mnist --mode accuracy
python tests/test_model.py --model ./models/fashion_best.pt --dataset fashion_mnist --mode accuracy
python tests/test_model.py --model ./models/cifar10_best.pt --dataset cifar10 --mode accuracyTerminal 1 - Start Training:
python train.py --dataset cifar10 --epochs 100 --batch-size 128Terminal 2 - Watch Logs:
# Windows
Get-Content ./logs/*.log -Wait -Tail 20
# Linux/Mac
tail -f ./logs/*.log# test_batch.py
import sys
sys.path.insert(0, '.')
import torch
from src.python.neuralforge.data.real_datasets import get_dataset
from src.python.neuralforge.models.resnet import ResNet18
# Load model and dataset
model = ResNet18(num_classes=10)
checkpoint = torch.load('./models/best_model.pt')
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()
dataset = get_dataset('cifar10', train=False)
# Test first 100 samples
correct = 0
for i in range(100):
image, label = dataset[i]
with torch.no_grad():
output = model(image.unsqueeze(0))
pred = output.argmax(1).item()
if pred == label:
correct += 1
print(f"Accuracy on 100 samples: {correct}%")CIFAR-10 (ResNet18, 50 epochs):
Epoch 50/50 | Train Loss: 0.3521 | Train Acc: 87.82% | Val Loss: 0.5123 | Val Acc: 84.31%
Training completed in 0.45 hours
MNIST (Simple CNN, 10 epochs):
Epoch 10/10 | Train Loss: 0.0234 | Train Acc: 99.21% | Val Loss: 0.0312 | Val Acc: 98.89%
Training completed in 0.08 hours
Fashion-MNIST (ResNet18, 30 epochs):
Epoch 30/30 | Train Loss: 0.2145 | Train Acc: 92.15% | Val Loss: 0.2834 | Val Acc: 90.42%
Training completed in 0.25 hours
# Use larger batch size (if GPU memory allows)
python train.py --dataset cifar10 --batch-size 256
# Reduce image size for faster experiments
config.image_size = 32 # Instead of 224# Smaller batch size
python train.py --dataset cifar10 --batch-size 64
# Disable AMP if issues
config.use_amp = False# Always validate before full training
python tests/quick_test.py
# Start with few epochs
python train.py --dataset cifar10 --epochs 5
# Monitor GPU usage
nvidia-smi -l 1# Set seed for reproducibility
python train.py --dataset cifar10 --seed 42python tests/quick_test.py- Validate setuppython train.py --dataset synthetic --epochs 3- Quick testpython train.py --dataset mnist --epochs 10- Real dataset
python train.py --dataset cifar10 --epochs 20- More complexpython tests/test_model.py --mode interactive- Test modelspython examples/train_cifar10.py- Custom script
python examples/neural_architecture_search.py- NAS- Create custom models in
src/python/neuralforge/nn/ - Implement custom CUDA kernels in
src/cuda/
After running these examples:
- Experiment with hyperparameters - learning rate, batch size, epochs
- Try different models - ResNet, EfficientNet, ViT
- Create custom architectures - Build your own networks
- Implement new features - Add your own datasets, layers
- Optimize performance - Profile, tune, accelerate
- QUICKSTART.md - Getting started guide
- DOCUMENTATION.md - Full API reference
- DATASETS.md - Dataset information
- FEATURES.md - Complete feature list
Happy experimenting! 🎉