Downloads · 30 days
0
Joana04/kvasir-unet
kvasir-unet is a machine learning model from Joana04. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This repository contains a U-Net model trained for gastrointestinal polyp segmentation using the Kvasir-SEG dataset. The model performs binary semantic segmentation, predicting a segmentation mask that identifies the…
Downloads · 30 days
0
Access
Public
Updated Mar 9, 2026
Parameters
31.1M
124 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors124 MB · 100%
From the Hugging Face model README
This repository contains a U-Net model trained for gastrointestinal polyp segmentation using the Kvasir-SEG dataset. The model performs binary semantic segmentation, predicting a segmentation mask that identifies the pixels corresponding to polyps in a gastrointestinal image. The architecture follows the standard encoder-decoder structure with skip connections:
The output mask represents the predicted probability oh each pixel belonging to a polyp class. Binarization uses a default threshold of 0.5.
This architecture is intended for educational purposes and for experimenting with the U-Net model for medical image segmentation.
Although the model performed well, there are some limitations: it was trained with only one dataset (Kvasir-SEG) and it may have a worse performance with images from different gastrointestinal datasets. It's not for clinical use.
The model weights are provided in the file model.safetensors.
Example usage in PyTorch:
from safetensors.torch import load_file
from model import UNet
model = UNet(in_channels=3, n_classes=1)
weights = load_file("model.safetensors")
model.load_state_dict(weights)
model.eval()
Expected input shape: (B,3,H,W) Expected output shape: (B,1,H,W)
The model was trained using the Kvasir-SEG dataset for polyp segmentation. The dataset is split into: train (model fitting), validation (model selection) and test (reserved for final reporting, not executed yet). The train dataset has 800 images, each one with a corresponding binary segmentation mask.
The training procedure was divided in:
Preprocessing:
Training configuration (using PyTorch + HuggingFace Trainer):
The model was trained using a combination of Dice Loss and Binary Cross-Entropy with Logits. Dice Loss can handle segmentation tasks with class imbalance as it focuses on maximazing the overlap between the predicted and the ground truth mask, but it can produce unstable gradients when the predicted regions are very small. BCE helps stabilize the training process by providing pixel-wise supervision and improving convergence, but it can't handle class imbalance very well. By combining both loss functions, there is a balance between region overlap optimization (Dice) with pixel-level classification accuracy (BCE), which may lead to better segmentation performances.
The model performance was evaluated using the the Dice coefficient and the IoU.