Spaces:
Runtime error
Runtime error
Usando from_pretrained_fastai para carga limpia
Browse files
app.py
CHANGED
|
@@ -9,14 +9,22 @@ categories = ['Bug', 'Dark', 'Dragon', 'Electric', 'Fairy', 'Fighting',
|
|
| 9 |
'Normal', 'Poison', 'Psychic', 'Rock', 'Steel', 'Water']
|
| 10 |
|
| 11 |
def load_clean_model(weights_path):
|
| 12 |
-
#
|
| 13 |
-
# Esto define la estructura
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Reconstruimos la arquitectura ConvNeXt Tiny
|
| 17 |
learn = vision_learner(dls, 'convnext_tiny', pretrained=False)
|
| 18 |
|
| 19 |
-
# Cargamos
|
| 20 |
# Fastai busca el archivo weights_path + '.pth'
|
| 21 |
learn.load(weights_path)
|
| 22 |
return learn
|
|
|
|
| 9 |
'Normal', 'Poison', 'Psychic', 'Rock', 'Steel', 'Water']
|
| 10 |
|
| 11 |
def load_clean_model(weights_path):
|
| 12 |
+
# Creamos un DataBlock manualmente.
|
| 13 |
+
# Esto define la estructura sin intentar leer ninguna lista.
|
| 14 |
+
dblock = DataBlock(
|
| 15 |
+
blocks=(ImageBlock, CategoryBlock(vocab=categories)),
|
| 16 |
+
item_tfms=Resize(126)
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Creamos un DataLoader vacío que solo sirve para inicializar el Learner
|
| 20 |
+
# Usamos dls de un objeto dummy que no requiere archivos reales
|
| 21 |
+
dls = dblock.dataloaders([PILImage.create(np.zeros((126,126,3), dtype=np.uint8))],
|
| 22 |
+
[categories[0]], bs=1)
|
| 23 |
|
| 24 |
# Reconstruimos la arquitectura ConvNeXt Tiny
|
| 25 |
learn = vision_learner(dls, 'convnext_tiny', pretrained=False)
|
| 26 |
|
| 27 |
+
# Cargamos los pesos (.pth)
|
| 28 |
# Fastai busca el archivo weights_path + '.pth'
|
| 29 |
learn.load(weights_path)
|
| 30 |
return learn
|