|
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 |
|
new_mask[(mask==29) | (mask==25)]=2 |
|
new_mask[(mask==74) | (mask==76)]=3 |
|
new_mask[mask==255]=4 |
|
|
|
|
|
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() |