Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,6 +39,37 @@ from huggingface_hub import from_pretrained_fastai
|
|
39 |
learn = from_pretrained_fastai("islasher/segm-grapes")
|
40 |
|
41 |
import torchvision.transforms as transforms
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
def transform_image(image):
|
43 |
my_transforms = transforms.Compose([transforms.ToTensor(),
|
44 |
transforms.Normalize(
|
|
|
39 |
learn = from_pretrained_fastai("islasher/segm-grapes")
|
40 |
|
41 |
import torchvision.transforms as transforms
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
class TargetMaskConvertTransform(ItemTransform):
|
46 |
+
def __init__(self):
|
47 |
+
pass
|
48 |
+
def encodes(self, x):
|
49 |
+
img,mask = x
|
50 |
+
|
51 |
+
#Convert to array
|
52 |
+
mask = np.array(mask)
|
53 |
+
|
54 |
+
|
55 |
+
# Changes: (codes= array(['Background', 'Leaves', 'Wood', 'Pole', 'Grape'], dtype='<U10'))
|
56 |
+
mask[mask==150]=1 #leaves
|
57 |
+
|
58 |
+
mask[mask==76]=3 #pole
|
59 |
+
mask[mask==74]=3 #pole
|
60 |
+
|
61 |
+
mask[mask==29]=2 #wood
|
62 |
+
mask[mask==25]=2 #wood
|
63 |
+
|
64 |
+
mask[mask==255]=4 #grape
|
65 |
+
|
66 |
+
mask[mask==0]=0
|
67 |
+
# Back to PILMask
|
68 |
+
mask = PILMask.create(mask)
|
69 |
+
return img, mask
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
def transform_image(image):
|
74 |
my_transforms = transforms.Compose([transforms.ToTensor(),
|
75 |
transforms.Normalize(
|