Spaces:
Sleeping
Sleeping
Fixed
Browse files- app.py +10 -3
- predictor.py +2 -17
app.py
CHANGED
|
@@ -22,12 +22,19 @@ def predict_image(img):
|
|
| 22 |
|
| 23 |
|
| 24 |
# Interfaz Gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
demo = gr.Interface(
|
| 26 |
fn=predict_image,
|
| 27 |
-
inputs=gr.Image(type="pil"),
|
| 28 |
outputs=gr.Textbox(label="Predicción"),
|
| 29 |
-
title="
|
| 30 |
-
|
| 31 |
)
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
# Interfaz Gradio
|
| 25 |
+
#demo = gr.Interface(
|
| 26 |
+
# fn=predict_image,
|
| 27 |
+
# inputs=gr.Image(type="pil"), # ← type="pil" = PIL.Image object
|
| 28 |
+
# outputs=gr.Textbox(label="Predicción"),
|
| 29 |
+
# title="🖋️ Clasificador Caligrafía CRNN",
|
| 30 |
+
# examples=None # Agrega ejemplos después
|
| 31 |
+
#)
|
| 32 |
demo = gr.Interface(
|
| 33 |
fn=predict_image,
|
| 34 |
+
inputs=gr.Image(type="pil"),
|
| 35 |
outputs=gr.Textbox(label="Predicción"),
|
| 36 |
+
title="Clasificador Caligrafía CRNN",
|
| 37 |
+
preprocess=False
|
| 38 |
)
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|
predictor.py
CHANGED
|
@@ -153,7 +153,7 @@ class CaligrafiaCRNN(nn.Module):
|
|
| 153 |
nn.Linear(256, num_classes)
|
| 154 |
)
|
| 155 |
|
| 156 |
-
def
|
| 157 |
features = self.cnn(x) # Bx128x4x16
|
| 158 |
B, C, H, W = features.shape
|
| 159 |
features = features.permute(0, 3, 1, 2).reshape(B, W, C*H) # Bx16x512
|
|
@@ -164,22 +164,7 @@ class CaligrafiaCRNN(nn.Module):
|
|
| 164 |
|
| 165 |
return self.classifier(pooled)
|
| 166 |
|
| 167 |
-
|
| 168 |
-
features = self.cnn(x) # Bx128xHxW (H,W cambian: local=[4,16], HF=[16,4])
|
| 169 |
-
B, C, H, W = features.shape
|
| 170 |
-
|
| 171 |
-
# 🔥 FIX: Detecta y corrige orientación automáticamente
|
| 172 |
-
if H > W: # CNN de HF está "girada"
|
| 173 |
-
features = features.permute(0, 1, 3, 2) # Intercambia H↔W
|
| 174 |
-
H, W = W, H # Actualiza dimensiones
|
| 175 |
-
|
| 176 |
-
# ✅ Ahora SIEMPRE Bx128x4x16 → reshape correcto
|
| 177 |
-
features = features.permute(0, 3, 1, 2).reshape(B, W, C*H) # Bx16x512
|
| 178 |
-
lstm_out, _ = self.lstm(features) # Bx16x512
|
| 179 |
-
attn_out, _ = self.attention(lstm_out, lstm_out, lstm_out)
|
| 180 |
-
pooled = attn_out.mean(dim=1) # Bx512
|
| 181 |
-
|
| 182 |
-
return self.classifier(pooled)
|
| 183 |
|
| 184 |
|
| 185 |
|
|
|
|
| 153 |
nn.Linear(256, num_classes)
|
| 154 |
)
|
| 155 |
|
| 156 |
+
def forward(self, x):
|
| 157 |
features = self.cnn(x) # Bx128x4x16
|
| 158 |
B, C, H, W = features.shape
|
| 159 |
features = features.permute(0, 3, 1, 2).reshape(B, W, C*H) # Bx16x512
|
|
|
|
| 164 |
|
| 165 |
return self.classifier(pooled)
|
| 166 |
|
| 167 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
|
| 170 |
|