File size: 5,205 Bytes
b8be0a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
---
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 Architecture](https://img.shields.io/badge/Architecture-DuckNet-blue)
![Framework](https://img.shields.io/badge/Framework-PyTorch-red)
![Task](https://img.shields.io/badge/Task-Medical%20Segmentation-green)
![Dataset](https://img.shields.io/badge/Dataset-Kvasir--SEG-orange)

## 🎯 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.