Cập nhật mã nguồn và file Colab Cache

This commit is contained in:
2026-07-16 19:32:43 +07:00
parent 25969cb0f5
commit a258db54cd
69 changed files with 3377 additions and 645 deletions
+51
View File
@@ -507,6 +507,57 @@ async def get_cloud_removal_methods():
}
@app.get("/api/ndvi-forecast/models")
async def list_ndvi_forecast_models():
"""Liệt kê các NDVI forecast models đã train"""
model_dir = Path("ndvi_forecast_model")
if not model_dir.exists():
return {"models": [], "count": 0}
models = []
# Search for all models
for model_file in list(model_dir.rglob("*.pth")) + list(model_dir.rglob("*.joblib")):
try:
import json
# Try to load metadata from .json sidecar file first
metadata_file = model_file.with_name(model_file.stem + "_info.json")
if metadata_file.exists():
try:
with open(metadata_file, 'r') as f:
metadata = json.load(f)
models.append({
"filename": model_file.name,
"path": str(model_file),
"model_type": metadata.get('model_type', 'Unknown'),
"target": metadata.get('target', 'NDVI'),
"rmse": metadata.get('rmse', 0),
"mae": metadata.get('mae', 0),
"epoch": metadata.get('epoch', 0),
"created": model_file.stat().st_mtime,
"size_mb": model_file.stat().st_size / (1024 * 1024),
})
continue
except Exception as e:
print(f"Error reading JSON {metadata_file}: {e}")
# Fallback for models without metadata
models.append({
"filename": model_file.name,
"path": str(model_file),
"model_type": "Unknown",
"created": model_file.stat().st_mtime,
"size_mb": model_file.stat().st_size / (1024 * 1024)
})
except Exception as e:
print(f"Error loading model info for {model_file}: {e}")
# Sort by creation time (newest first)
models.sort(key=lambda x: x['created'], reverse=True)
return {"models": models, "count": len(models)}
@app.get("/api/cloud-removal/models")
async def list_cloud_removal_models():
"""Liệt kê các cloud removal models đã train"""