Downloads · 30 days
15
15% of all-time downloads
ibrahim313/ducknet-polyp-segmentation
ducknet-polyp-segmentation is a machine learning model from ibrahim313. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
Downloads · 30 days
15
15% of all-time downloads
All-time downloads
99
Public
Repo size
31.1 MB
Likes
1
Public
Click a slice to open those files.
.bin31.1 MB · 100%
From the Hugging Face model README
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.
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()
This Duck-Net implementation features:
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()
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.
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}
}
| 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) |
For questions or issues, please open an issue in the repository or contact the model author.