A modular TensorFlow/Keras Image segmentation library
Project description
Seg - Professional Semantic Segmentation Library
A professional, modular, and extensible semantic segmentation library built on TensorFlow 2.x that demonstrates exceptional software engineering practices and system design prowess.
🚀 Key Features
Architecture Excellence
- Modular Design: Clean separation between encoders, decoders, losses, and metrics
- Extensible Framework: Easy addition of new components through registry patterns
- Professional API: Intuitive factory functions and comprehensive configuration options
- Type Safety: Full type hints and runtime validation
Model Architectures
- Multiple Encoders: ResNet, VGG, EfficientNet, MobileNet, DenseNet, and custom architectures
- Advanced Decoders: U-Net, U-Net++, DeepLabV3+, and extensible decoder framework
- Flexible Configuration: Dynamic model building with extensive customization options
Loss Functions & Metrics
- Comprehensive Losses: Dice, IoU, Focal, Tversky, Lovász, and combination losses
- Professional Metrics: IoU, Dice coefficient, precision, recall, F1-score, specificity
- Task-Specific Recommendations: Automated metric selection based on task type
Data Pipeline
- Optimized Loading: High-performance tf.data pipelines with prefetching and caching
- Advanced Augmentations: Geometric and photometric augmentations with mask consistency
- Multiple Formats: Support for directories, TFRecords, and custom data sources
📦 Installation
pip install seg
For development installation:
git clone https://github.com/example/seg.git
cd seg
pip install -e ".[dev,docs,examples]"
🏗️ Quick Start
Basic Usage
import seg
# Create a model with clean API
model = seg.get_model(
encoder="resnet50",
decoder="unet",
num_classes=21,
input_shape=(256, 256, 3),
encoder_weights="imagenet"
)
# Configure with appropriate loss and metrics
model.compile(
optimizer="adam",
loss=seg.get_loss("dice_loss"),
metrics=[seg.get_metric("iou"), seg.get_metric("f1_score")]
)
# Train the model
model.fit(train_dataset, validation_data=val_dataset, epochs=50)
Advanced Configuration
# Custom model with advanced configuration
model = seg.get_model(
encoder="efficientnet-b0",
decoder="deeplabv3plus",
num_classes=1,
input_shape=(512, 512, 3),
decoder_config={
"aspp_filters": 512,
"atrous_rates": [6, 12, 18, 24]
},
activation="sigmoid"
)
# Combination loss for optimal performance
loss = seg.get_loss("combo_loss", losses={
"dice_loss": 0.5,
"focal_loss": 0.3,
"binary_crossentropy": 0.2
})
# Comprehensive metrics
metrics = [
seg.get_metric("iou", threshold=0.5),
seg.get_metric("dice_coefficient"),
seg.get_metric("precision"),
seg.get_metric("recall")
]
model.compile(optimizer="adam", loss=loss, metrics=metrics)
Professional Data Pipeline
from seg.utils import DataPipeline, get_default_augmentations
# Setup data pipeline
pipeline = DataPipeline(
input_shape=(256, 256, 3),
num_classes=21,
batch_size=16
)
# Add augmentations
for aug in get_default_augmentations(strong=True):
pipeline.add_augmentation(aug)
# Load data
train_ds, val_ds = pipeline.load_from_directories(
image_dir="data/images",
mask_dir="data/masks",
validation_split=0.2
)
🏛️ Architecture Overview
seg/
├── __init__.py # Main API exports
├── models/ # Model architectures
│ ├── __init__.py
│ ├── base.py # Core SegmentationModel class
│ ├── encoders.py # Encoder implementations
│ └── decoders.py # Decoder implementations
├── losses.py # Loss function collection
├── metrics.py # Evaluation metrics
└── utils/ # Utilities
├── __init__.py
└── data.py # Data pipeline & preprocessing
Design Patterns
- Registry Pattern: Extensible component registration
- Factory Pattern: Clean object creation APIs
- Strategy Pattern: Configurable algorithms
- Builder Pattern: Complex model configuration
🎯 Supported Components
Encoders
- ResNet: ResNet50, ResNet101
- VGG: VGG16, VGG19
- EfficientNet: EfficientNet-B0, B1
- MobileNet: MobileNetV2
- DenseNet: DenseNet121
- Custom: Extensible custom architectures
Decoders
- U-Net: Classic U-Net with skip connections
- U-Net++: Nested U-Net with dense connections
- DeepLabV3+: ASPP with encoder-decoder structure
Loss Functions
- Classic: Binary/Categorical Cross-entropy
- Overlap: Dice, IoU (Jaccard)
- Focal: Focal loss for class imbalance
- Advanced: Tversky, Focal Tversky, Lovász
- Combination: Multi-loss optimization
Metrics
- Overlap: IoU, Dice coefficient, Mean IoU
- Classification: Precision, Recall, F1-score, Specificity
- Pixel-wise: Pixel accuracy
💡 Advanced Features
Model Flexibility
# Easy encoder swapping
model.encoder = seg.get_encoder("efficientnet-b1", input_shape=(512, 512, 3))
# Dynamic decoder configuration
model.decoder_config.update({"filters": [512, 256, 128, 64]})
# Freezing/unfreezing encoder
model.encoder.trainable = False
Information Retrieval
# Get component information
encoder_info = seg.models.get_encoder_info("resnet50")
decoder_info = seg.models.get_decoder_info("unet")
loss_info = seg.losses.get_loss_info("dice_loss")
# List available components
print("Encoders:", seg.models.list_encoders())
print("Decoders:", seg.models.list_decoders())
print("Losses:", seg.losses.list_losses())
print("Metrics:", seg.metrics.list_metrics())
Recommended Configurations
# Get task-specific recommendations
metrics = seg.metrics.get_recommended_metrics("medical", num_classes=1)
# Returns: ["dice_coefficient", "iou", "precision", "recall", "specificity"]
🧪 Testing & Quality
- Comprehensive Tests: 95%+ code coverage
- Type Checking: Full mypy compliance
- Code Quality: Black, isort, flake8
- CI/CD: Automated testing and deployment
- Documentation: Sphinx with examples
📖 Examples & Tutorials
- Basic Segmentation
- Medical Image Segmentation
- Multi-class Segmentation
- Custom Architecture
- Data Pipeline
🤝 Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Development Setup
git clone https://github.com/example/seg.git
cd seg
pip install -e ".[dev]"
pre-commit install
Adding New Components
# Adding a new encoder
from seg.models.encoders import EncoderRegistry
@EncoderRegistry.register("my_encoder")
def build_my_encoder(input_shape, weights=None, **kwargs):
# Implementation here
return model
# Adding a new loss
from seg.losses import LossRegistry
@LossRegistry.register("my_loss")
class MyLoss(keras.losses.Loss):
# Implementation here
pass
📄 License
This project is licensed under the MIT License - see LICENSE file for details.
🙏 Acknowledgments
- TensorFlow team for the excellent framework
- Research community for segmentation innovations
- Open source contributors
📈 Performance
- Memory Efficient: Optimized for large images
- GPU Accelerated: Full CUDA support
- Distributed Training: Multi-GPU support
- Production Ready: Tested at scale
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 seg_anushqaa-0.1.0.tar.gz.
File metadata
- Download URL: seg_anushqaa-0.1.0.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
543ac243a05ad66c325eba3d816592e90194de2b219c6367dfef513c182333fb
|
|
| MD5 |
94119debb42c4e6cec02b411355cb460
|
|
| BLAKE2b-256 |
92bf61b9e5e5f774d18abb61179d9606f3d0f37c24b4b30b2dc3b10bd28c4425
|
File details
Details for the file seg_anushqaa-0.1.0-py3-none-any.whl.
File metadata
- Download URL: seg_anushqaa-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6b34615c3efab295d2d8290bc3ce585ac9f1832d74168db6bb3fa285d4d23bc
|
|
| MD5 |
a247978f52a16e44ed10cf2123e01bcb
|
|
| BLAKE2b-256 |
91ccab5c883775ecec37ca5b2ae83a8a082c0259acfedd72f9c97572f1810c6d
|