Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,31 @@ from fastai.vision.all import *
|
|
4 |
import PIL
|
5 |
import torchvision.transforms as transforms
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
repo_id = "paascorb/practica3_Segmentation"
|
8 |
|
9 |
learner = from_pretrained_fastai(repo_id)
|
|
|
4 |
import PIL
|
5 |
import torchvision.transforms as transforms
|
6 |
|
7 |
+
class TargetMaskConvertTransform(ItemTransform):
|
8 |
+
def __init__(self):
|
9 |
+
pass
|
10 |
+
def encodes(self, x):
|
11 |
+
img,mask = x
|
12 |
+
|
13 |
+
#Convert to array
|
14 |
+
mask = np.array(mask)
|
15 |
+
|
16 |
+
# Aquí definimos cada clase en la máscara
|
17 |
+
# uva:
|
18 |
+
mask[mask==255]=1
|
19 |
+
# hojas:
|
20 |
+
mask[mask==150]=2
|
21 |
+
# conductores:
|
22 |
+
mask[mask==76]=3
|
23 |
+
mask[mask==74]=3
|
24 |
+
# madera:
|
25 |
+
mask[mask==29]=4
|
26 |
+
mask[mask==25]=4
|
27 |
+
|
28 |
+
# Back to PILMask
|
29 |
+
mask = PILMask.create(mask)
|
30 |
+
return img, mask
|
31 |
+
|
32 |
repo_id = "paascorb/practica3_Segmentation"
|
33 |
|
34 |
learner = from_pretrained_fastai(repo_id)
|