Update app.py
Browse files
app.py
CHANGED
|
@@ -28,8 +28,12 @@ os.system('pip install -U gradio')
|
|
| 28 |
|
| 29 |
import gradio as gr
|
| 30 |
|
| 31 |
-
|
| 32 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def transform_image(image):
|
| 34 |
my_transforms = transforms.Compose([transforms.ToTensor(),
|
| 35 |
transforms.Normalize(
|
|
@@ -72,8 +76,6 @@ from albumentations import (
|
|
| 72 |
ShiftScaleRotate
|
| 73 |
)
|
| 74 |
|
| 75 |
-
def get_y_fn (x):
|
| 76 |
-
return Path(str(x).replace("Images","Labels").replace("color","gt").replace(".jpg",".png"))
|
| 77 |
|
| 78 |
class SegmentationAlbumentationsTransform(ItemTransform):
|
| 79 |
split_idx = 0
|
|
@@ -86,7 +88,6 @@ class SegmentationAlbumentationsTransform(ItemTransform):
|
|
| 86 |
aug = self.aug(image=np.array(img), mask=np.array(mask))
|
| 87 |
return PILImage.create(aug["image"]), PILMask.create(aug["mask"])
|
| 88 |
|
| 89 |
-
#Cargamos el modelo
|
| 90 |
repo_id = "maviced/practica3"
|
| 91 |
learn = from_pretrained_fastai(repo_id)
|
| 92 |
model = learn.model
|
|
@@ -121,10 +122,3 @@ def predict(img):
|
|
| 121 |
gr.Interface(fn=predict, inputs=["image"], outputs=["image"],
|
| 122 |
examples=['color_154.jpg','color_155.jpg']).launch(share=True)
|
| 123 |
|
| 124 |
-
|
| 125 |
-
# Creamos la interfaz y la lanzamos.
|
| 126 |
-
#gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(480, 640)), outputs=gr.inputs.Image(shape=(480, 640))).launch(share=False) #,examples=['color_155.jpg','color_154 (1).jpg']
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
# Creamos la interfaz y la lanzamos.
|
| 130 |
-
#gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(480, 640)), outputs=gr.inputs.Image(shape=(480, 640)),examples=['color_155.jpg','color_154.jpg']).launch(share=False)
|
|
|
|
| 28 |
|
| 29 |
import gradio as gr
|
| 30 |
|
| 31 |
+
|
| 32 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 33 |
+
|
| 34 |
+
def get_y_fn (x):
|
| 35 |
+
return Path(str(x).replace("Images","Labels").replace("color","gt").replace(".jpg",".png"))
|
| 36 |
+
|
| 37 |
def transform_image(image):
|
| 38 |
my_transforms = transforms.Compose([transforms.ToTensor(),
|
| 39 |
transforms.Normalize(
|
|
|
|
| 76 |
ShiftScaleRotate
|
| 77 |
)
|
| 78 |
|
|
|
|
|
|
|
| 79 |
|
| 80 |
class SegmentationAlbumentationsTransform(ItemTransform):
|
| 81 |
split_idx = 0
|
|
|
|
| 88 |
aug = self.aug(image=np.array(img), mask=np.array(mask))
|
| 89 |
return PILImage.create(aug["image"]), PILMask.create(aug["mask"])
|
| 90 |
|
|
|
|
| 91 |
repo_id = "maviced/practica3"
|
| 92 |
learn = from_pretrained_fastai(repo_id)
|
| 93 |
model = learn.model
|
|
|
|
| 122 |
gr.Interface(fn=predict, inputs=["image"], outputs=["image"],
|
| 123 |
examples=['color_154.jpg','color_155.jpg']).launch(share=True)
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|