Downloads · 30 days
0
hugginglearners/kvasir-seg
kvasir-seg is a machine learning model from hugginglearners. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for fastai.
Fastai unet created with unetlearner using resnet34
Downloads · 30 days
0
Access
Public
Updated Jul 15, 2022
Repo size
323 MB
Likes
0
Public
Click a slice to open those files.
.pkl174 MB · 99%
From the Hugging Face model README
Fastai unet created with unet_learner using resnet34
This is only used for demonstration of fine tuning capabilities with fastai. It may be useful for further research. This model should not be used for gastrointestinal polyp diagnosis.
The model was trained on Kvasir SEG dataset. Kvasir SEG is an open-access dataset of gastrointestinal polyp images and corresponding segmentation masks, manually annotated and verified by an experienced gastroenterologist.
20% of the data set were used as validation set and 80% as training set.
Masks were converted to 1 bit images: 0 for background and 1 for mask using
Path('/notebooks/Kvasir-SEG/masks1b-binary').mkdir(parents=True, exist_ok=True)
for img_path in tqdm(get_image_files(path/'masks')):
img = Image.open(img_path)
thresh = 127
fn = lambda x : 1 if x > thresh else 0
img1b = img.convert('L').point(fn)
img1b.save(path/'masks1b-binary'/f'{img_path.stem}.png')
SegmentationDataloaders were used to create fastai data loaders
def label_func(fn): return path/'masks1b-binary'/f'{fn.stem}.png'
dls = SegmentationDataLoaders.from_label_func(
path, bs=24, fnames = get_image_files(path/'images'),
label_func = label_func,
codes = list(range(2)),
item_tfms=Resize(320),
batch_tfms=aug_transforms(size=224, flip_vert=True)
)
An sample of training images:

Create learner with Dice and JaccardCoeff metrics
learn = unet_learner(dls, resnet34, metrics=[Dice, JaccardCoeff]).to_fp16()
Learning rate finder

Fine tuning for 12 epochs
learn.fine_tune(12, 1e-4)
epoch train_loss valid_loss dice jaccard_coeff time
0 0.582160 0.433768 0.593044 0.421508 00:38
epoch train_loss valid_loss dice jaccard_coeff time
0 0.307588 0.261374 0.712569 0.553481 00:38
1 0.261775 0.232007 0.714458 0.555764 00:38
2 0.246054 0.227708 0.781048 0.640754 00:38
3 0.224612 0.185920 0.796701 0.662097 00:39
4 0.208768 0.179064 0.821945 0.697714 00:39
5 0.192531 0.171336 0.816464 0.689851 00:39
6 0.177166 0.167357 0.820771 0.696023 00:39
7 0.168222 0.158182 0.838388 0.721745 00:39
8 0.155157 0.161950 0.829525 0.708709 00:39
9 0.148792 0.164533 0.828383 0.707043 00:38
10 0.143541 0.158669 0.833519 0.714559 00:39
11 0.140083 0.159437 0.832745 0.713422 00:38

Visualization of results
Target/Prediction

Top losses

huggingface_hub.__version__
'0.8.1'
fastai.__version__
'2.6.3'