File size: 971 Bytes
8d1d038
 
 
5570c58
2933508
 
 
 
 
 
 
8d1d038
 
2933508
 
 
 
 
 
 
 
 
8d1d038
 
 
 
5570c58
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from huggingface_hub import from_pretrained_fastai
import gradio as gr
from fastai.vision.all import *

class TargetMaskConvertTransform(ItemTransform):
    def __init__(self):
        pass
    def encodes(self, x):
        img,mask = x
        mask = np.array(mask)
        new_mask = np.zeros_like(mask, dtype=np.uint8)


        new_mask[mask==150]=1                   #Clase Leaves
        new_mask[(mask==29) | (mask==25)]=2     #Clase Wood
        new_mask[(mask==74) | (mask==76)]=3     #Clase Pole
        new_mask[mask==255]=4                   #Clase Wood


        mask = PILMask.create(new_mask)
        return img, mask


repo_id = "joortif/Practica3"

learn = from_pretrained_fastai(repo_id)

def segment_image(img):
    pred, _, _ = learn.predict(img)
    return pred

interface = gr.Interface(
    fn=segment_image,
    inputs=gr.Image(type="pil"),
    outputs=gr.Image(type="numpy"),
    title="Segmentación Semántica con FastAI",
)

interface.launch()