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.30.tar.gz (34.6 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.30-py3-none-any.whl (41.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gcpds-cv-pykit-0.1.0.30.tar.gz
  • Upload date:
  • Size: 34.6 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.30.tar.gz
Algorithm Hash digest
SHA256 ea8b21ec24e9b53e01ee95c56c1a1ac01dae6905518d84af38f3f503f014b119
MD5 f4d89d8a5bd564df8ef32e855feee347
BLAKE2b-256 7369f6e5600c91e6abb0e8858d3b80010c338d725c7b07c930685fb8f16b42ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gcpds_cv_pykit-0.1.0.30-py3-none-any.whl
Algorithm Hash digest
SHA256 e0cdb343ad0dae583765764a4a14cf41d91492e611be3cf03b34f12a0a4c57a7
MD5 bb34d580d7fd93b6e0ad8b950b5a19d3
BLAKE2b-256 83ba4646347681ed3f2fcdd7164659c427e18ca164415b74708dac4e5b24a276

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