A comprehensive toolkit for computer vision and segmentation tasks
Project description
GCPDS Computer Vision Python Kit
A comprehensive toolkit for computer vision and segmentation tasks, developed by the GCPDS Team. This package provides state-of-the-art tools for training, evaluating, and deploying segmentation models with support for various architectures, loss functions, and performance metrics.
๐ Features
- Segmentation Models: Support for UNet and other popular architectures
- Multiple Loss Functions: DICE, Cross Entropy, Focal Loss, and Tversky Loss
- Performance Evaluation: Comprehensive metrics including Dice, Jaccard, Sensitivity, and Specificity
- Training Pipeline: Complete training workflow with validation and monitoring
- Experiment Tracking: Integration with Weights & Biases (wandb)
- Mixed Precision Training: Automatic Mixed Precision (AMP) support for faster training
- Flexible Configuration: YAML/JSON-based configuration system
- Visualization Tools: Built-in visualization utilities for model predictions
- Memory Management: Efficient memory handling and cleanup utilities
๐ Requirements
- Python >= 3.8
- PyTorch >= 2.0.0
- CUDA-compatible GPU (recommended)
๐ง Installation
From PyPI (when available)
pip install gcpds-cv-pykit
From Source
git clone https://github.com/UN-GCPDS/gcpds-cv-pykit.git
cd gcpds-cv-pykit
pip install -e .
Development Installation
git clone https://github.com/UN-GCPDS/gcpds-cv-pykit.git
cd gcpds-cv-pykit
pip install -e ".[dev,docs]"
๐ฆ Dependencies
Core Dependencies
torch>=2.0.0- Deep learning frameworktorchvision>=0.15.0- Computer vision utilitiesnumpy>=1.21.0- Numerical computingopencv-python>=4.6.0- Image processingmatplotlib>=3.5.0- Plotting and visualizationwandb>=0.15.0- Experiment trackingtqdm>=4.64.0- Progress barsPillow>=9.0.0- Image handlingscipy>=1.9.0- Scientific computingpandas>=1.4.0- Data manipulation
Optional Dependencies
- Development:
pytest,black,flake8,isort - Documentation:
sphinx,sphinx-rtd-theme
๐๏ธ Project Structure
gcpds_cv_pykit/
โโโ baseline/
โ โโโ trainers/ # Training utilities
โ โโโ models/ # Model architectures
โ โโโ losses/ # Loss functions
โ โโโ dataloaders/ # Data loading utilities
โ โโโ performance_model.py # Model evaluation
โโโ crowd/ # Crowd-specific implementations
โโโ datasets/ # Dataset utilities
โโโ visuals/ # Visualization tools
๐ Quick Start
Basic Training Example
from gcpds_cv_pykit.baseline.trainers import SegmentationModel_Trainer
from torch.utils.data import DataLoader
# Define your configuration
config = {
'Model': 'UNet',
'Backbone': 'resnet34',
'Number of classes': 2,
'Loss Function': 'DICE',
'Optimizer': 'Adam',
'Learning Rate': 0.001,
'Epochs': 100,
'Batch Size': 8,
'Input size': [3, 256, 256],
'AMP': True,
'Device': 'cuda'
}
# Initialize trainer
trainer = SegmentationModel_Trainer(
train_loader=train_dataloader,
valid_loader=valid_dataloader,
config=config
)
# Start training
trainer.start()
Model Evaluation Example
from gcpds_cv_pykit.baseline import PerformanceModels
# Evaluate trained model
evaluator = PerformanceModels(
model=trained_model,
test_dataset=test_dataloader,
config=config,
save_results=True
)
Custom Loss Function
from gcpds_cv_pykit.baseline.losses import DICELoss, FocalLoss
# DICE Loss
dice_loss = DICELoss(smooth=1.0, reduction='mean')
# Focal Loss
focal_loss = FocalLoss(alpha=0.25, gamma=2.0, reduction='mean')
๐ Supported Models
- UNet: Classic U-Net architecture with various backbone options
- Backbones: ResNet, EfficientNet, and more
- Pretrained weights support
- Customizable activation functions
๐ฏ Loss Functions
- DICE Loss: Optimized for segmentation tasks
- Cross Entropy: Standard classification loss
- Focal Loss: Addresses class imbalance
- Tversky Loss: Generalization of Dice loss
๐ Metrics
The toolkit provides comprehensive evaluation metrics:
- Dice Coefficient: Overlap-based similarity measure
- Jaccard Index (IoU): Intersection over Union
- Sensitivity (Recall): True positive rate
- Specificity: True negative rate
All metrics are calculated both globally and per-class.
๐ง Configuration
The toolkit uses dictionary-based configuration. Key parameters include:
config = {
# Model Configuration
'Model': 'UNet',
'Backbone': 'resnet34',
'Pretrained': True,
'Number of classes': 2,
'Input size': [3, 256, 256],
# Training Configuration
'Loss Function': 'DICE',
'Optimizer': 'Adam',
'Learning Rate': 0.001,
'Epochs': 100,
'Batch Size': 8,
# Advanced Options
'AMP': True, # Automatic Mixed Precision
'Device': 'cuda',
'Wandb monitoring': ['api_key', 'project_name', 'run_name']
}
๐ Experiment Tracking
Integration with Weights & Biases for experiment tracking:
config['Wandb monitoring'] = [
'your_wandb_api_key',
'your_project_name',
'experiment_name'
]
๐จ Visualization
Built-in visualization tools for:
- Training/validation curves
- Model predictions vs ground truth
- Metric evolution across epochs
- Sample predictions
๐งช Testing
Run the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=gcpds_cv_pykit
# Run specific test file
pytest tests/test_models.py
๐ Documentation
Build documentation locally:
cd docs
make html
๐ค Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone the repository
git clone https://github.com/UN-GCPDS/gcpds-cv-pykit.git
cd gcpds-cv-pykit
# Install in development mode
pip install -e ".[dev]"
# Run code formatting
black gcpds_cv_pykit/
isort gcpds_cv_pykit/
# Run linting
flake8 gcpds_cv_pykit/
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ฅ Authors
- GCPDS Team - Initial work - gcpds_man@unal.edu.co
๐ Acknowledgments
- PyTorch team for the excellent deep learning framework
- The computer vision community for inspiration and best practices
- Contributors and users of this toolkit
๐ Support
- Issues: GitHub Issues
- Documentation: Read the Docs
- Email: your-email@example.com
๐ Changelog
Version 0.1.0 (Alpha)
- Initial release
- Basic UNet implementation
- Core loss functions
- Training and evaluation pipeline
- Weights & Biases integration
Note: This project is in active development. APIs may change between versions. Please check the documentation for the latest updates.
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 gcpds-cv-pykit-0.1.0.29.tar.gz.
File metadata
- Download URL: gcpds-cv-pykit-0.1.0.29.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
587af63dacf23d1ad80d39f900216477bd7d03d99990c7f2175af9afafc107b3
|
|
| MD5 |
5a933a52650381e0eaabc4b6ef401f93
|
|
| BLAKE2b-256 |
75ca3955a1e6e8f694db07dedfdd1102906afedcd44865196fe02afab6236fcb
|
File details
Details for the file gcpds_cv_pykit-0.1.0.29-py3-none-any.whl.
File metadata
- Download URL: gcpds_cv_pykit-0.1.0.29-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbd80bc5950b2e046220681f8d432f0d772514b840cea671257fe5868f41a9c1
|
|
| MD5 |
4dd7b3cb977247699652811e79714672
|
|
| BLAKE2b-256 |
a7d35a8184274b749393e3cc88d252c3f2107873d34d2f267762b0e4418524c2
|