|
--- |
|
license: apache-2.0 |
|
tags: |
|
- medical-imaging |
|
- polyp-detection |
|
- colonoscopy |
|
- segmentation |
|
- pytorch |
|
- ducknet |
|
- kvasir-seg |
|
task: image-segmentation |
|
widget: |
|
- src: https://example.com/colonoscopy-image.jpg |
|
example_title: "Colonoscopy Image" |
|
--- |
|
|
|
# π¦ Duck-Net: Polyp Segmentation Model |
|
|
|
 |
|
 |
|
 |
|
 |
|
|
|
## π― Model Description |
|
|
|
This is a **Duck-Net** model fine-tuned for polyp segmentation in colonoscopy images. The model is based on a U-Net architecture with Duck-inspired multi-scale feature extraction blocks for superior medical image segmentation performance. |
|
|
|
### π Model Performance |
|
|
|
- **Validation Dice Coefficient**: 92.88% |
|
- **Validation Jaccard Index**: 48.92% |
|
- **Dataset**: Kvasir-SEG (1000 colonoscopy images) |
|
- **Training Time**: ~83 minutes on GPU |
|
- **Model Size**: ~29.6 MB |
|
|
|
## π Quick Start |
|
|
|
```python |
|
from huggingface_hub import hf_hub_download |
|
import torch |
|
import torch.nn as nn |
|
|
|
# Define the model architecture |
|
class DuckNet(nn.Module): |
|
def __init__(self, img_size=(256, 256), num_classes=3): |
|
super(DuckNet, self).__init__() |
|
# ... (model definition) |
|
|
|
def forward(self, x): |
|
# ... (forward pass) |
|
return torch.sigmoid(output) |
|
|
|
# Download and load model |
|
model_path = hf_hub_download( |
|
repo_id="ibrahim313/ducknet-polyp-segmentation", |
|
filename="pytorch_model.bin" |
|
) |
|
|
|
model = DuckNet(img_size=(256, 256), num_classes=3) |
|
model.load_state_dict(torch.load(model_path, map_location='cpu')) |
|
model.eval() |
|
|
|
# Inference |
|
import albumentations as A |
|
from albumentations.pytorch import ToTensorV2 |
|
|
|
transform = A.Compose([ |
|
A.Resize(256, 256), |
|
A.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), |
|
ToTensorV2() |
|
]) |
|
|
|
# Process image |
|
transformed = transform(image=your_image) |
|
input_tensor = transformed['image'].unsqueeze(0) |
|
|
|
with torch.no_grad(): |
|
prediction = model(input_tensor) |
|
binary_mask = (prediction > 0.5).float() |
|
``` |
|
|
|
## ποΈ Model Architecture |
|
|
|
This Duck-Net implementation features: |
|
|
|
1. **Encoder-Decoder Structure**: U-Net based architecture |
|
2. **Multi-scale Features**: Duck-inspired feature extraction |
|
3. **Skip Connections**: Direct feature transfer between encoder and decoder |
|
4. **Batch Normalization**: Stable training and inference |
|
5. **Sigmoid Activation**: Multi-class segmentation output |
|
|
|
### Key Features |
|
|
|
- **Input Size**: 256Γ256Γ3 (RGB images) |
|
- **Output**: 256Γ256Γ3 (Multi-class segmentation mask) |
|
- **Parameters**: ~7,766,051 |
|
- **Architecture**: Duck-Net (U-Net variant) |
|
|
|
## π Training Details |
|
|
|
### Dataset |
|
- **Source**: Kvasir-SEG dataset |
|
- **Total Images**: 1000 colonoscopy images with polyp annotations |
|
- **Split**: 800 training, 100 validation, 100 test |
|
- **Classes**: Background, Polyp, Other tissue |
|
|
|
### Training Configuration |
|
- **Optimizer**: Adam (lr=0.001) |
|
- **Loss Function**: Jaccard Coefficient Loss |
|
- **Batch Size**: 8 |
|
- **Epochs**: 50 |
|
- **Hardware**: Tesla P100 GPU |
|
- **Framework**: Originally TensorFlow/Keras, converted to PyTorch |
|
|
|
## π» Usage Example |
|
|
|
```python |
|
import cv2 |
|
import numpy as np |
|
from PIL import Image |
|
|
|
def predict_polyp(image_path, model, threshold=0.5): |
|
# Load image |
|
image = cv2.imread(image_path) |
|
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) |
|
|
|
# Preprocess |
|
transformed = transform(image=image) |
|
input_tensor = transformed['image'].unsqueeze(0) |
|
|
|
# Predict |
|
model.eval() |
|
with torch.no_grad(): |
|
prediction = model(input_tensor) |
|
binary_mask = (prediction > threshold).float() |
|
|
|
return binary_mask.squeeze().numpy() |
|
``` |
|
|
|
## β οΈ Medical Disclaimer |
|
|
|
**Important**: This model is for research and educational purposes only. It should not be used for clinical diagnosis or treatment decisions. Always consult qualified medical professionals for clinical applications. |
|
|
|
## π Citation |
|
|
|
If you use this model in your research, please cite: |
|
|
|
```bibtex |
|
@misc{ducknet_polyp_2024, |
|
title={Duck-Net for Polyp Segmentation in Colonoscopy Images}, |
|
author={Ibrahim313}, |
|
year={2024}, |
|
howpublished={Hugging Face Model Hub}, |
|
url={https://huggingface.co/ibrahim313/ducknet-polyp-segmentation} |
|
} |
|
``` |
|
|
|
## π₯ Model Card Authors |
|
|
|
- **Developed by**: ibrahim313 |
|
- **Model Type**: Convolutional Neural Network (Duck-Net) |
|
- **License**: Apache 2.0 |
|
- **Repository**: https://huggingface.co/ibrahim313/ducknet-polyp-segmentation |
|
|
|
## π§ Technical Specifications |
|
|
|
| Specification | Value | |
|
|---------------|-------| |
|
| Input Resolution | 256Γ256 | |
|
| Input Channels | 3 (RGB) | |
|
| Output Channels | 3 (Multi-class) | |
|
| Model Size | ~29.6 MB | |
|
| Parameters | 7,766,051 | |
|
| Inference Time | <1 second (CPU) | |
|
| Memory Usage | ~2GB (inference) | |
|
|
|
## π₯ Applications |
|
|
|
- Colonoscopy image analysis |
|
- Polyp detection and segmentation |
|
- Medical imaging research |
|
- Computer-aided diagnosis (research only) |
|
|
|
## π€ Contact |
|
|
|
For questions or issues, please open an issue in the repository or contact the model author. |
|
|