Add Configuration file: fix_yaml.py
Browse files- fix_yaml.py +78 -0
fix_yaml.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Script para corregir la configuración YAML del dataset
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import yaml
|
| 7 |
+
import os
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
def fix_dataset_config():
|
| 11 |
+
"""Corrige el archivo de configuración YAML"""
|
| 12 |
+
|
| 13 |
+
config_path = "/home/leonel/sistema_polinizador/Dataset/Classification/dataset_config.yaml"
|
| 14 |
+
|
| 15 |
+
print("🔧 CORRIGIENDO CONFIGURACIÓN YAML")
|
| 16 |
+
print("=" * 50)
|
| 17 |
+
|
| 18 |
+
# Verificar que existe el archivo
|
| 19 |
+
if not os.path.exists(config_path):
|
| 20 |
+
print(f"❌ No se encontró el archivo: {config_path}")
|
| 21 |
+
return False
|
| 22 |
+
|
| 23 |
+
# Verificar estructura del dataset
|
| 24 |
+
dataset_base_path = "/home/leonel/sistema_polinizador/Dataset/Classification"
|
| 25 |
+
train_path = os.path.join(dataset_base_path, "Train")
|
| 26 |
+
val_path = os.path.join(dataset_base_path, "Validation")
|
| 27 |
+
test_path = os.path.join(dataset_base_path, "Test")
|
| 28 |
+
|
| 29 |
+
print(f"📁 Verificando estructura del dataset:")
|
| 30 |
+
print(f" Base: {dataset_base_path} - {'✅' if os.path.exists(dataset_base_path) else '❌'}")
|
| 31 |
+
print(f" Train: {train_path} - {'✅' if os.path.exists(train_path) else '❌'}")
|
| 32 |
+
print(f" Validation: {val_path} - {'✅' if os.path.exists(val_path) else '❌'}")
|
| 33 |
+
print(f" Test: {test_path} - {'✅' if os.path.exists(test_path) else '❌'}")
|
| 34 |
+
|
| 35 |
+
if not all(os.path.exists(p) for p in [dataset_base_path, train_path, val_path, test_path]):
|
| 36 |
+
print("❌ Faltan carpetas del dataset")
|
| 37 |
+
return False
|
| 38 |
+
|
| 39 |
+
# Obtener clases del directorio Train
|
| 40 |
+
class_names = []
|
| 41 |
+
if os.path.exists(train_path):
|
| 42 |
+
class_names = sorted([d for d in os.listdir(train_path)
|
| 43 |
+
if os.path.isdir(os.path.join(train_path, d))])
|
| 44 |
+
|
| 45 |
+
print(f"🏷️ Clases encontradas: {len(class_names)}")
|
| 46 |
+
for i, name in enumerate(class_names):
|
| 47 |
+
print(f" {i}: {name}")
|
| 48 |
+
|
| 49 |
+
# Crear configuración corregida
|
| 50 |
+
corrected_config = {
|
| 51 |
+
'path': dataset_base_path, # Ruta absoluta al directorio base
|
| 52 |
+
'train': 'Train', # Ruta relativa desde 'path'
|
| 53 |
+
'val': 'Validation', # Ruta relativa desde 'path'
|
| 54 |
+
'test': 'Test', # Ruta relativa desde 'path'
|
| 55 |
+
'nc': len(class_names), # Número de clases
|
| 56 |
+
'names': {i: name for i, name in enumerate(class_names)} # Mapeo índice -> nombre
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
# Guardar configuración corregida
|
| 60 |
+
with open(config_path, 'w') as f:
|
| 61 |
+
yaml.dump(corrected_config, f, default_flow_style=False, sort_keys=False)
|
| 62 |
+
|
| 63 |
+
print(f"\n✅ Configuración corregida guardada en: {config_path}")
|
| 64 |
+
|
| 65 |
+
# Mostrar contenido del archivo corregido
|
| 66 |
+
print(f"\n📄 Contenido del archivo YAML:")
|
| 67 |
+
with open(config_path, 'r') as f:
|
| 68 |
+
content = f.read()
|
| 69 |
+
print(content)
|
| 70 |
+
|
| 71 |
+
return True
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
success = fix_dataset_config()
|
| 75 |
+
if success:
|
| 76 |
+
print("\n🎯 Configuración corregida. Ahora puedes ejecutar el entrenamiento.")
|
| 77 |
+
else:
|
| 78 |
+
print("\n❌ Error corrigiendo la configuración.")
|