Update README.md
Browse files
README.md
CHANGED
@@ -3,30 +3,88 @@ tags:
|
|
3 |
- fastai
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
🥳 Congratulations on hosting your fastai model on the Hugging Face Hub!
|
9 |
|
10 |
-
|
11 |
-
|
12 |
|
13 |
-
|
|
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
|
|
|
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
|
|
30 |
|
31 |
-
|
32 |
-
|
|
|
3 |
- fastai
|
4 |
---
|
5 |
|
6 |
+
# Model card
|
|
|
|
|
7 |
|
8 |
+
## Model description
|
9 |
+
Fastai `unet` created with `unet_learner` using `resnet34`
|
10 |
|
11 |
+
## Intended uses & limitations
|
12 |
+
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.
|
13 |
|
14 |
+
## Training and evaluation data
|
15 |
+
The model was trained on [Kvasir SEG dataset](https://datasets.simula.no/kvasir-seg/). Kvasir SEG is an open-access dataset of gastrointestinal polyp images and corresponding segmentation masks, manually annotated and verified by an experienced gastroenterologist.
|
16 |
+
20% of the data set were used as validation set and 80% as training set.
|
17 |
+
|
18 |
+
### Model training details:
|
19 |
|
20 |
+
#### Data pre-processing
|
21 |
+
Masks were converted to 1 bit images: 0 for background and 1 for mask using
|
22 |
+
```python
|
23 |
+
Path('/notebooks/Kvasir-SEG/masks1b-binary').mkdir(parents=True, exist_ok=True)
|
24 |
+
for img_path in tqdm(get_image_files(path/'masks')):
|
25 |
+
img = Image.open(img_path)
|
26 |
+
thresh = 127
|
27 |
+
fn = lambda x : 1 if x > thresh else 0
|
28 |
+
img1b = img.convert('L').point(fn)
|
29 |
+
img1b.save(path/'masks1b-binary'/f'{img_path.stem}.png')
|
30 |
+
```
|
31 |
+
#### Data loaders
|
32 |
+
`SegmentationDataloaders` were used to create fastai data loaders
|
33 |
+
```python
|
34 |
+
def label_func(fn): return path/'masks1b-binary'/f'{fn.stem}.png'
|
35 |
+
dls = SegmentationDataLoaders.from_label_func(
|
36 |
+
path, bs=24, fnames = get_image_files(path/'images'),
|
37 |
+
label_func = label_func,
|
38 |
+
codes = list(range(2)),
|
39 |
+
item_tfms=Resize(320),
|
40 |
+
batch_tfms=aug_transforms(size=224, flip_vert=True)
|
41 |
+
)
|
42 |
+
```
|
43 |
+
An sample of training images:
|
44 |
+

|
45 |
|
46 |
+
#### Learner
|
47 |
+
Create learner with Dice and JaccardCoeff metrics
|
48 |
+
```python
|
49 |
+
learn = unet_learner(dls, resnet34, metrics=[Dice, JaccardCoeff]).to_fp16()
|
50 |
+
```
|
51 |
|
52 |
+
#### Learning rate
|
53 |
+
Learning rate finder
|
54 |
+

|
55 |
|
56 |
+
#### Fine tuning
|
57 |
+
Fine tuning for 12 epochs
|
58 |
+
`learn.fine_tune(12, 1e-4)`
|
59 |
+
```
|
60 |
+
epoch train_loss valid_loss dice jaccard_coeff time
|
61 |
+
0 0.582160 0.433768 0.593044 0.421508 00:38
|
62 |
+
epoch train_loss valid_loss dice jaccard_coeff time
|
63 |
+
0 0.307588 0.261374 0.712569 0.553481 00:38
|
64 |
+
1 0.261775 0.232007 0.714458 0.555764 00:38
|
65 |
+
2 0.246054 0.227708 0.781048 0.640754 00:38
|
66 |
+
3 0.224612 0.185920 0.796701 0.662097 00:39
|
67 |
+
4 0.208768 0.179064 0.821945 0.697714 00:39
|
68 |
+
5 0.192531 0.171336 0.816464 0.689851 00:39
|
69 |
+
6 0.177166 0.167357 0.820771 0.696023 00:39
|
70 |
+
7 0.168222 0.158182 0.838388 0.721745 00:39
|
71 |
+
8 0.155157 0.161950 0.829525 0.708709 00:39
|
72 |
+
9 0.148792 0.164533 0.828383 0.707043 00:38
|
73 |
+
10 0.143541 0.158669 0.833519 0.714559 00:39
|
74 |
+
11 0.140083 0.159437 0.832745 0.713422 00:38
|
75 |
+
```
|
76 |
+

|
77 |
|
78 |
+
#### Results
|
79 |
+
Visualization of results
|
80 |
+

|
81 |
|
82 |
+
Top losses
|
83 |
+

|
84 |
|
85 |
+
#### Libraries used:
|
86 |
+
`huggingface_hub.__version__`
|
87 |
+
`'0.8.1'`
|
88 |
|
89 |
+
`fastai.__version__`
|
90 |
+
`'2.6.3'`
|