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.33.tar.gz (30.4 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.33-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gcpds-cv-pykit-0.1.0.33.tar.gz
  • Upload date:
  • Size: 30.4 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.33.tar.gz
Algorithm Hash digest
SHA256 cd04cf15bd019e2133ade03057693ea50d881d16bbe9df25a793e2f3ab67d877
MD5 c28f3a47f8731713095ad6b54a397773
BLAKE2b-256 c3c3e9a3a2b6bc36d4760da18eb5969cb146329405aa25480a8956f50fc6a73b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gcpds_cv_pykit-0.1.0.33-py3-none-any.whl
Algorithm Hash digest
SHA256 9b985d8190f689cba6f2c1582dc00d900d328e21abb294b7a700acb303fbec84
MD5 a6f14539ab4801e18b9fad753a1197d9
BLAKE2b-256 572aca31252b7e896143adf9235f8ac46c28ce48b625a4233ad927d2f24c2f29

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