fix: align ML service labels with training order
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
59877bc17f
commit
ed8cecc3f5
@@ -44,6 +44,9 @@ async def predict(file: UploadFile = File(...)) -> PredictionResponse:
|
||||
except ImageDecodeError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
except Exception as exc:
|
||||
import logging
|
||||
|
||||
logging.exception("Prediction failed")
|
||||
raise HTTPException(status_code=500, detail="Prediction failed") from exc
|
||||
|
||||
return PredictionResponse(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from io import BytesIO
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
@@ -7,7 +8,7 @@ from PIL import Image, UnidentifiedImageError
|
||||
import tensorflow as tf
|
||||
|
||||
|
||||
LABELS = ["Bercak Daun", "Hawar Daun", "Karat Daun", "Daun Sehat"]
|
||||
LABELS = ["Bercak Daun", "Daun Sehat", "Karat Daun", "Hawar Daun"]
|
||||
SERVICE_NAME = "zeavis-ml-service"
|
||||
SERVICE_VERSION = "0.1.0"
|
||||
|
||||
@@ -40,6 +41,7 @@ class ModelService:
|
||||
except Exception as exc:
|
||||
self.model = None
|
||||
self.load_error = str(exc)
|
||||
logging.exception("Failed to load ML model from %s", self.model_path)
|
||||
|
||||
def preprocess(self, image_bytes: bytes) -> np.ndarray:
|
||||
try:
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import unittest
|
||||
|
||||
from model import LABELS
|
||||
|
||||
|
||||
class ModelServiceTests(unittest.TestCase):
|
||||
def test_labels_match_training_class_order_with_display_names(self) -> None:
|
||||
self.assertEqual(
|
||||
LABELS,
|
||||
["Bercak Daun", "Daun Sehat", "Karat Daun", "Hawar Daun"],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user