πŸ¦† Duck-Net: Polyp Segmentation Model

Model Architecture Framework Task Dataset

🎯 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

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

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:

@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

πŸ”§ 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.

Downloads last month
6
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support