Skip to main content

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 framework
  • torchvision>=0.15.0 - Computer vision utilities
  • numpy>=1.21.0 - Numerical computing
  • opencv-python>=4.6.0 - Image processing
  • matplotlib>=3.5.0 - Plotting and visualization
  • wandb>=0.15.0 - Experiment tracking
  • tqdm>=4.64.0 - Progress bars
  • Pillow>=9.0.0 - Image handling
  • scipy>=1.9.0 - Scientific computing
  • pandas>=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:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

๐Ÿ™ 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

๐Ÿ”„ 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcpds-cv-pykit-0.1.0.27.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcpds_cv_pykit-0.1.0.27-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file gcpds-cv-pykit-0.1.0.27.tar.gz.

File metadata

  • Download URL: gcpds-cv-pykit-0.1.0.27.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for gcpds-cv-pykit-0.1.0.27.tar.gz
Algorithm Hash digest
SHA256 c7c573904eadb0c2f3c0ad7832422c81ad80fd88a5b3d5d35a2cbc67021e513e
MD5 f98d3839992391b7f044d366e649e7f7
BLAKE2b-256 6e6766d1c3fdbe6e38d350ee67c2ce565aecaa1741094bb3784bfac00281e02d

See more details on using hashes here.

File details

Details for the file gcpds_cv_pykit-0.1.0.27-py3-none-any.whl.

File metadata

File hashes

Hashes for gcpds_cv_pykit-0.1.0.27-py3-none-any.whl
Algorithm Hash digest
SHA256 638988acdad39edf10dfb5b8a65166af32e55a05106214074710a8cf5c2f27e8
MD5 be70c67dc0e9662be4a21cf2cb3e48c9
BLAKE2b-256 e4e5baabe4d8874f83881e61ae133765538399c8b13b5a32e5871858e2c1c2e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page