ibrahim313 commited on
Commit
b8be0a7
Β·
verified Β·
1 Parent(s): 2840c1d

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +186 -0
README.md ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - medical-imaging
5
+ - polyp-detection
6
+ - colonoscopy
7
+ - segmentation
8
+ - pytorch
9
+ - ducknet
10
+ - kvasir-seg
11
+ task: image-segmentation
12
+ widget:
13
+ - src: https://example.com/colonoscopy-image.jpg
14
+ example_title: "Colonoscopy Image"
15
+ ---
16
+
17
+ # πŸ¦† Duck-Net: Polyp Segmentation Model
18
+
19
+ ![Model Architecture](https://img.shields.io/badge/Architecture-DuckNet-blue)
20
+ ![Framework](https://img.shields.io/badge/Framework-PyTorch-red)
21
+ ![Task](https://img.shields.io/badge/Task-Medical%20Segmentation-green)
22
+ ![Dataset](https://img.shields.io/badge/Dataset-Kvasir--SEG-orange)
23
+
24
+ ## 🎯 Model Description
25
+
26
+ 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.
27
+
28
+ ### πŸ“Š Model Performance
29
+
30
+ - **Validation Dice Coefficient**: 92.88%
31
+ - **Validation Jaccard Index**: 48.92%
32
+ - **Dataset**: Kvasir-SEG (1000 colonoscopy images)
33
+ - **Training Time**: ~83 minutes on GPU
34
+ - **Model Size**: ~29.6 MB
35
+
36
+ ## πŸš€ Quick Start
37
+
38
+ ```python
39
+ from huggingface_hub import hf_hub_download
40
+ import torch
41
+ import torch.nn as nn
42
+
43
+ # Define the model architecture
44
+ class DuckNet(nn.Module):
45
+ def __init__(self, img_size=(256, 256), num_classes=3):
46
+ super(DuckNet, self).__init__()
47
+ # ... (model definition)
48
+
49
+ def forward(self, x):
50
+ # ... (forward pass)
51
+ return torch.sigmoid(output)
52
+
53
+ # Download and load model
54
+ model_path = hf_hub_download(
55
+ repo_id="ibrahim313/ducknet-polyp-segmentation",
56
+ filename="pytorch_model.bin"
57
+ )
58
+
59
+ model = DuckNet(img_size=(256, 256), num_classes=3)
60
+ model.load_state_dict(torch.load(model_path, map_location='cpu'))
61
+ model.eval()
62
+
63
+ # Inference
64
+ import albumentations as A
65
+ from albumentations.pytorch import ToTensorV2
66
+
67
+ transform = A.Compose([
68
+ A.Resize(256, 256),
69
+ A.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
70
+ ToTensorV2()
71
+ ])
72
+
73
+ # Process image
74
+ transformed = transform(image=your_image)
75
+ input_tensor = transformed['image'].unsqueeze(0)
76
+
77
+ with torch.no_grad():
78
+ prediction = model(input_tensor)
79
+ binary_mask = (prediction > 0.5).float()
80
+ ```
81
+
82
+ ## πŸ—οΈ Model Architecture
83
+
84
+ This Duck-Net implementation features:
85
+
86
+ 1. **Encoder-Decoder Structure**: U-Net based architecture
87
+ 2. **Multi-scale Features**: Duck-inspired feature extraction
88
+ 3. **Skip Connections**: Direct feature transfer between encoder and decoder
89
+ 4. **Batch Normalization**: Stable training and inference
90
+ 5. **Sigmoid Activation**: Multi-class segmentation output
91
+
92
+ ### Key Features
93
+
94
+ - **Input Size**: 256Γ—256Γ—3 (RGB images)
95
+ - **Output**: 256Γ—256Γ—3 (Multi-class segmentation mask)
96
+ - **Parameters**: ~7,766,051
97
+ - **Architecture**: Duck-Net (U-Net variant)
98
+
99
+ ## πŸ“‹ Training Details
100
+
101
+ ### Dataset
102
+ - **Source**: Kvasir-SEG dataset
103
+ - **Total Images**: 1000 colonoscopy images with polyp annotations
104
+ - **Split**: 800 training, 100 validation, 100 test
105
+ - **Classes**: Background, Polyp, Other tissue
106
+
107
+ ### Training Configuration
108
+ - **Optimizer**: Adam (lr=0.001)
109
+ - **Loss Function**: Jaccard Coefficient Loss
110
+ - **Batch Size**: 8
111
+ - **Epochs**: 50
112
+ - **Hardware**: Tesla P100 GPU
113
+ - **Framework**: Originally TensorFlow/Keras, converted to PyTorch
114
+
115
+ ## πŸ’» Usage Example
116
+
117
+ ```python
118
+ import cv2
119
+ import numpy as np
120
+ from PIL import Image
121
+
122
+ def predict_polyp(image_path, model, threshold=0.5):
123
+ # Load image
124
+ image = cv2.imread(image_path)
125
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
126
+
127
+ # Preprocess
128
+ transformed = transform(image=image)
129
+ input_tensor = transformed['image'].unsqueeze(0)
130
+
131
+ # Predict
132
+ model.eval()
133
+ with torch.no_grad():
134
+ prediction = model(input_tensor)
135
+ binary_mask = (prediction > threshold).float()
136
+
137
+ return binary_mask.squeeze().numpy()
138
+ ```
139
+
140
+ ## ⚠️ Medical Disclaimer
141
+
142
+ **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.
143
+
144
+ ## πŸ“š Citation
145
+
146
+ If you use this model in your research, please cite:
147
+
148
+ ```bibtex
149
+ @misc{ducknet_polyp_2024,
150
+ title={Duck-Net for Polyp Segmentation in Colonoscopy Images},
151
+ author={Ibrahim313},
152
+ year={2024},
153
+ howpublished={Hugging Face Model Hub},
154
+ url={https://huggingface.co/ibrahim313/ducknet-polyp-segmentation}
155
+ }
156
+ ```
157
+
158
+ ## πŸ‘₯ Model Card Authors
159
+
160
+ - **Developed by**: ibrahim313
161
+ - **Model Type**: Convolutional Neural Network (Duck-Net)
162
+ - **License**: Apache 2.0
163
+ - **Repository**: https://huggingface.co/ibrahim313/ducknet-polyp-segmentation
164
+
165
+ ## πŸ”§ Technical Specifications
166
+
167
+ | Specification | Value |
168
+ |---------------|-------|
169
+ | Input Resolution | 256Γ—256 |
170
+ | Input Channels | 3 (RGB) |
171
+ | Output Channels | 3 (Multi-class) |
172
+ | Model Size | ~29.6 MB |
173
+ | Parameters | 7,766,051 |
174
+ | Inference Time | <1 second (CPU) |
175
+ | Memory Usage | ~2GB (inference) |
176
+
177
+ ## πŸ₯ Applications
178
+
179
+ - Colonoscopy image analysis
180
+ - Polyp detection and segmentation
181
+ - Medical imaging research
182
+ - Computer-aided diagnosis (research only)
183
+
184
+ ## 🀝 Contact
185
+
186
+ For questions or issues, please open an issue in the repository or contact the model author.