Update app.py
Browse files
app.py
CHANGED
|
@@ -11,13 +11,9 @@ class TargetMaskConvertTransform(ItemTransform):
|
|
| 11 |
def __init__(self): pass
|
| 12 |
def encodes(self, x): return x
|
| 13 |
|
| 14 |
-
# Transformaci贸n de Albumentations (SOLUCI脫N
|
| 15 |
class SegmentationAlbumentationsTransform(ItemTransform):
|
| 16 |
-
split_idx = 0 #
|
| 17 |
-
# Al poner split_idx=0, le decimos a FastAI:
|
| 18 |
-
# "Esta transformaci贸n es SOLO para el conjunto de TRAIN".
|
| 19 |
-
# Por tanto, al predecir una foto nueva, se saltar谩 esta clase y no dar谩 error.
|
| 20 |
-
|
| 21 |
def __init__(self, aug):
|
| 22 |
pass
|
| 23 |
def encodes(self, x):
|
|
@@ -49,14 +45,17 @@ def predict(img):
|
|
| 49 |
# Procesamiento a Numpy
|
| 50 |
mask_data = np.array(pred_mask, dtype=np.uint8)
|
| 51 |
h, w = mask_data.shape
|
|
|
|
|
|
|
| 52 |
color_mask = np.zeros((h, w, 3), dtype=np.uint8)
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
# 1:Hojas(Verde), 2:Madera(
|
| 56 |
-
|
| 57 |
-
color_mask[mask_data ==
|
| 58 |
-
color_mask[mask_data ==
|
| 59 |
-
color_mask[mask_data ==
|
|
|
|
| 60 |
|
| 61 |
return color_mask
|
| 62 |
|
|
@@ -66,7 +65,7 @@ iface = gr.Interface(
|
|
| 66 |
inputs=gr.Image(type="pil"),
|
| 67 |
outputs=gr.Image(type="numpy"),
|
| 68 |
title="Segmentaci贸n de Uvas (ResNet50)",
|
| 69 |
-
description="Modelo capaz de detectar: Uvas (
|
| 70 |
examples=[]
|
| 71 |
)
|
| 72 |
|
|
|
|
| 11 |
def __init__(self): pass
|
| 12 |
def encodes(self, x): return x
|
| 13 |
|
| 14 |
+
# Transformaci贸n de Albumentations (SOLUCI脫N FIX)
|
| 15 |
class SegmentationAlbumentationsTransform(ItemTransform):
|
| 16 |
+
split_idx = 0 # Esta l铆nea evita que se ejecute en inferencia
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def __init__(self, aug):
|
| 18 |
pass
|
| 19 |
def encodes(self, x):
|
|
|
|
| 45 |
# Procesamiento a Numpy
|
| 46 |
mask_data = np.array(pred_mask, dtype=np.uint8)
|
| 47 |
h, w = mask_data.shape
|
| 48 |
+
|
| 49 |
+
# Creamos la imagen RGB vac铆a
|
| 50 |
color_mask = np.zeros((h, w, 3), dtype=np.uint8)
|
| 51 |
|
| 52 |
+
# --- PALETA DE COLORES ACTUALIZADA ---
|
| 53 |
+
# 0:Fondo(Negro), 1:Hojas(Verde), 2:Madera(Azul), 3:Poste(Rojo), 4:Uvas(Blanco)
|
| 54 |
+
|
| 55 |
+
color_mask[mask_data == 1] = [0, 255, 0] # Hojas -> Verde
|
| 56 |
+
color_mask[mask_data == 2] = [0, 0, 255] # Madera -> Azul (Tu cambio)
|
| 57 |
+
color_mask[mask_data == 3] = [255, 0, 0] # Poste -> Rojo (Tu cambio)
|
| 58 |
+
color_mask[mask_data == 4] = [255, 255, 255] # Uvas -> Blanco (Tu cambio)
|
| 59 |
|
| 60 |
return color_mask
|
| 61 |
|
|
|
|
| 65 |
inputs=gr.Image(type="pil"),
|
| 66 |
outputs=gr.Image(type="numpy"),
|
| 67 |
title="Segmentaci贸n de Uvas (ResNet50)",
|
| 68 |
+
description="Modelo capaz de detectar: Uvas (Blanco), Hojas (Verde), Madera (Azul) y Postes (Rojo).",
|
| 69 |
examples=[]
|
| 70 |
)
|
| 71 |
|