Advanced Computer Vision Toolkit for Image Classification
Project description
Swajay CV Toolkit ๐
Advanced Computer Vision Toolkit for State-of-the-Art Image Classification
A comprehensive, production-ready toolkit featuring cutting-edge loss functions, model architectures, augmentation strategies, and training pipelines. Designed for researchers, practitioners, and Kaggle competitors who want to achieve state-of-the-art results with minimal code.
๐ฏ Key Features
๐ฅ Advanced Loss Functions
- Focal Loss - Handle class imbalance effectively
- Label Smoothing Cross Entropy - Improve generalization
- Polynomial Loss - Enhanced convergence properties
- Mixed Loss - Optimal combination of multiple loss functions
- Automatic class weight calculation for imbalanced datasets
๐๏ธ Universal Model Architectures
- Auto-adaptive models - Automatically adjust to any number of classes
- Multiple architectures - ConvNeXt, EfficientNet, ResNet, Vision Transformers
- Smart classifier heads - Optimal architecture for your dataset size
- Ensemble support - Combine multiple models for better performance
๐ญ Professional Augmentations
- Competition-grade augmentations - Albumentations-based pipeline
- MixUp & CutMix - Advanced mixing strategies
- Test-Time Augmentation (TTA) - Boost inference accuracy
- 4 intensity levels - From lightweight to competition-grade
๐๏ธ Advanced Training Pipeline
- Mixed precision training - 2x faster with lower memory usage
- Differential learning rates - Optimal rates for backbone vs classifier
- Smart early stopping - Prevent overfitting automatically
- Comprehensive metrics - Track everything that matters
๐ Quick Start
Installation
pip install swajay-cv-toolkit
Basic Usage
import torch
from swajay_cv_toolkit import create_model, get_loss_function, AdvancedTrainer
from torch.utils.data import DataLoader
# Create model for any number of classes
model = create_model('convnext_large', num_classes=10)
# Get advanced loss function
criterion = get_loss_function('mixed') # Combines focal + label smoothing + poly
# Create optimizer
optimizer = torch.optim.AdamW(model.parameters(), lr=1e-3)
# Advanced trainer with all the bells and whistles
trainer = AdvancedTrainer(
model=model,
criterion=criterion,
optimizer=optimizer,
mixed_precision=True,
gradient_clip_norm=1.0
)
# Train with automatic early stopping
history = trainer.fit(
train_loader=train_loader,
val_loader=val_loader,
epochs=50,
early_stopping_patience=10
)
Complete Pipeline Example
from swajay_cv_toolkit import *
# 1. Setup
seed_everything(42)
device = setup_device()
# 2. Data augmentation
aug_config = get_augmentation_preset('competition', image_size=224)
train_dataset = AdvancedDataset(raw_dataset, aug_config['train_transform'])
# 3. Model creation
model = create_model('convnext_large', num_classes=20).to(device)
# 4. Advanced training components
criterion = get_loss_function('mixed')
optimizer = create_optimizer(model, 'adamw', lr=1e-3, differential_lr=True)
scheduler = create_scheduler(optimizer, 'cosine', total_steps=1000)
# 5. Train with MixUp/CutMix
mixup_cutmix = MixupCutmix(mixup_alpha=0.2, cutmix_alpha=1.0)
trainer = AdvancedTrainer(model, criterion, optimizer, scheduler)
history = trainer.fit(train_loader, val_loader, epochs=30, mixup_cutmix=mixup_cutmix)
# 6. Test-Time Augmentation for final predictions
tta_predictor = TTAPredictor(model, device)
predictions = tta_predictor.predict_with_tta(test_dataset, aug_config['tta_transforms'])
๐ฏ Supported Use Cases
โ Works on ANY Image Classification Task
- Medical Imaging - X-rays, MRIs, pathology slides
- Satellite Imagery - Land use, crop monitoring, disaster assessment
- Manufacturing - Quality control, defect detection
- Retail & E-commerce - Product categorization, visual search
- Security - Face recognition, object identification
- Agriculture - Plant disease detection, crop classification
- Wildlife & Conservation - Species identification, monitoring
- Food & Nutrition - Recipe classification, nutritional analysis
- Academic Research - Any custom image classification dataset
๐ Dataset Requirements
Just organize your data like this:
your_dataset/
โโโ class1/
โ โโโ image1.jpg
โ โโโ image2.jpg
โ โโโ ...
โโโ class2/
โ โโโ image1.jpg
โ โโโ ...
โโโ class3/
โโโ ...
That's it! The toolkit handles everything else automatically.
๐ Comprehensive Examples
Example 1: CIFAR-10 Classification
import torchvision.datasets as datasets
from swajay_cv_toolkit import *
# Load CIFAR-10
train_data = datasets.CIFAR10(root='./data', train=True, download=True)
test_data = datasets.CIFAR10(root='./data', train=False, download=True)
# Quick setup with presets
config = {
'model': 'efficientnet_b4',
'num_classes': 10,
'image_size': 224
}
# One-line training
model, history = quick_train(
train_data, test_data,
preset='competition',
**config
)
Example 2: Custom Medical Dataset
# Your medical imaging dataset
train_data = datasets.ImageFolder('./medical_images/train')
test_data = datasets.ImageFolder('./medical_images/test')
# Specialized setup for medical images
model = create_model('convnext_large', num_classes=len(train_data.classes))
criterion = get_loss_function('focal', alpha=2, gamma=2) # Good for imbalanced medical data
# Conservative augmentations for medical data
aug_config = get_augmentation_preset('standard', image_size=384)
# Train with higher resolution for medical precision
trainer = AdvancedTrainer(model, criterion, optimizer)
history = trainer.fit(train_loader, val_loader, epochs=100)
Example 3: Ensemble for Maximum Accuracy
# Create ensemble of different architectures
models = [
create_model('convnext_large', num_classes=20),
create_model('efficientnet_b7', num_classes=20),
create_model('vit_large_patch16_224', num_classes=20)
]
ensemble = EnsembleModel(models, weights=[0.4, 0.35, 0.25])
# Train ensemble or individual models
for i, model in enumerate(models):
print(f"Training model {i+1}/3...")
trainer = AdvancedTrainer(model, criterion, optimizer)
trainer.fit(train_loader, val_loader, epochs=30)
๐ง Advanced Features
๐ฏ Automatic Configuration
- Auto-detect classes - No need to count manually
- Auto-size networks - Optimal architecture for your data size
- Auto-balance classes - Handle imbalanced datasets automatically
- Auto-tune hyperparameters - Smart defaults that work
๐ฌ Research-Grade Components
All components are based on peer-reviewed research:
- ConvNeXt: Liu et al., 2022 - A ConvNet for the 2020s
- Focal Loss: Lin et al., 2017 - Focal Loss for Dense Object Detection
- Label Smoothing: Szegedy et al., 2016 - Rethinking the Inception Architecture
- MixUp: Zhang et al., 2017 - mixup: Beyond Empirical Risk Minimization
- Test-Time Augmentation: He et al., 2015 - Deep Residual Learning for Image Recognition
- AdamW: Loshchilov & Hutter, 2017 - Decoupled Weight Decay Regularization
๐ Production Ready
- Memory efficient - Automatic mixed precision
- GPU optimized - Efficient data loading and processing
- Reproducible - Comprehensive seed management
- Robust - Extensive error handling and validation
- Scalable - Works from laptop to multi-GPU setups
๐ฎ Presets for Every Use Case
'lightweight' - Fast Development
- EfficientNet-B2, basic augmentations, 20 epochs
- Perfect for prototyping and quick experiments
'standard' - Balanced Performance
- ConvNeXt-Base, medium augmentations, 30 epochs
- Great balance of speed and accuracy
'competition' - Maximum Accuracy
- ConvNeXt-Large, aggressive augmentations, TTA, 40 epochs
- For when you need the absolute best results
'research' - Experimental Features
- Latest architectures, experimental techniques
- For pushing the boundaries
๐ Documentation
๐ Quick References
๐ Detailed Guides
- Loss Functions Guide - When to use which loss
- Model Architecture Guide - Choosing the right model
- Augmentation Guide - Augmentation strategies
- Training Guide - Advanced training techniques
- Troubleshooting - Common issues and solutions
๐ค Contributing
We welcome contributions! Here's how:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run tests:
pytest tests/ - Format code:
black swajay_cv_toolkit/ - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
๐ Bug Reports
Found a bug? Open an issue with:
- Python version and OS
- Full error traceback
- Minimal code to reproduce
- Dataset information (if relevant)
๐ก Feature Requests
Have an idea? Request a feature with:
- Use case description
- Expected behavior
- Example code (if possible)
๐ ๏ธ Technical Requirements
Minimum Requirements
- Python: 3.8+
- PyTorch: 1.12.0+
- CUDA: Optional but recommended
- RAM: 8GB+ (16GB+ recommended)
- Storage: 2GB for dependencies
Recommended Setup
- GPU: RTX 3080+ or Tesla V100+
- RAM: 32GB+
- Python: 3.10+
- CUDA: 11.7+
Dependencies
All dependencies are automatically installed:
torch>=1.12.0
torchvision>=0.13.0
timm>=0.6.0
albumentations>=1.3.0
opencv-python-headless>=4.6.0
numpy>=1.21.0
scikit-learn>=1.1.0
pandas>=1.4.0
๐ฌ Get Help
- Documentation: swajay-cv-toolkit.readthedocs.io
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: swajay@example.com
๐ Show Your Support
If this toolkit helps you:
- โญ Star the repository
- ๐ฆ Tweet about it
- ๐ Write a blog post
- ๐ฃ๏ธ Tell your colleagues
- ๐ Sponsor the project
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Citation
If you use this toolkit in your research, please cite:
@software{swajay_cv_toolkit,
title={Swajay CV Toolkit: Advanced Computer Vision for Image Classification},
author={Swajay},
year={2024},
url={https://github.com/swajayresources/swajay-cv-toolkit},
version={1.0.0}
}
๐ Acknowledgments
Special thanks to:
- PyTorch Team - For the amazing framework
- TIMM contributors - For the model implementations
- Albumentations team - For the augmentation library
- Research community - For the foundational papers
- Beta testers - For feedback and bug reports
- Contributors - For making this project better
Made with โค๏ธ by Swajay
โญ Star on GitHub โข ๐ Documentation โข ๐ Report Bug โข ๐ก Request Feature
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swajay_cv_toolkit-1.0.9.tar.gz.
File metadata
- Download URL: swajay_cv_toolkit-1.0.9.tar.gz
- Upload date:
- Size: 30.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f52b48557905b3bc2587245834d2c811cf4049d9be8deb753497c133617f280
|
|
| MD5 |
e8785fb519ae2c6fb381900a10cfcaf4
|
|
| BLAKE2b-256 |
4c13ae1ed68a5f10733593076d0d5defcf35698f748ac2c4b5a2ab7c7355f92e
|
File details
Details for the file swajay_cv_toolkit-1.0.9-py3-none-any.whl.
File metadata
- Download URL: swajay_cv_toolkit-1.0.9-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
524c51d84d8055812cdcdd281b08d8ddba2f535eaa4f771a13cfd588a19301b7
|
|
| MD5 |
0d20505ce7fc8919b24a86b69c1d6cbe
|
|
| BLAKE2b-256 |
f0d6afa4525b4fbab0dc0ea2fac5630cefd6c312d15f6a71de5e2df23dcfeee0
|