diff --git a/packages/mlopspython-inference/mlopspython_inference/inference_pillow.py b/packages/mlopspython-inference/mlopspython_inference/inference_pillow.py index 63e5a9d3..1062cf6b 100644 --- a/packages/mlopspython-inference/mlopspython_inference/inference_pillow.py +++ b/packages/mlopspython-inference/mlopspython_inference/inference_pillow.py @@ -22,9 +22,24 @@ def load_image(filename: str|BytesIO): BASE_PATH = Path(__file__).resolve().parent +class IModel(): + def predict(self, img)->np.ndarray: + pass + +class ModelPillow(IModel): + def __init__(self, model_path: str): + self.model = load_model(model_path) + + def predict(self, img)->np.ndarray: + return self.model.predict(img) + +class ModelMock(IModel): + def predict(self, img)->np.ndarray: + return np.array([[1, 0, 0]]) + class Inference: - def __init__(self, logging, model_path: str): + def __init__(self, logging, model: IModel): self.logger = logging.getLogger(__name__) self.model = load_model(model_path) diff --git a/packages/mlopspython-inference/tests/input/model/final_model.keras b/packages/mlopspython-inference/tests/input/model/final_model.keras new file mode 100644 index 00000000..0545a188 Binary files /dev/null and b/packages/mlopspython-inference/tests/input/model/final_model.keras differ diff --git a/packages/mlopspython-inference/tests/test_inference.py b/packages/mlopspython-inference/tests/test_inference.py index 27cc7656..0ee9022a 100644 --- a/packages/mlopspython-inference/tests/test_inference.py +++ b/packages/mlopspython-inference/tests/test_inference.py @@ -1,6 +1,8 @@ import logging from pathlib import Path import pytest +from .mocks import ModelMock + from mlopspython_inference.inference_pillow import Inference @@ -8,15 +10,16 @@ input_directory = BASE_PATH / "input" -@pytest.mark.skip(reason="Modèle lourd / GPU non requis sur CI. Enlever ce skip si nécessaire.") +#@pytest.mark.skip(reason="Modèle lourd / GPU non requis sur CI. Enlever ce skip si nécessaire.") def test_inference_runs_with_sample_model_and_image(): - model_path = input_directory / "model" / "final_model.h5" + model_path = input_directory / "model" / "final_model.keras" image_path = input_directory / "images" / "cat.png" assert model_path.is_file(), "Modèle de test manquant" assert image_path.is_file(), "Image de test manquante" - inference = Inference(logging, str(model_path)) + #model = ModelMock() + inference = Inference(logging, model) result = inference.execute(str(image_path)) assert result["prediction"] in {"Cat", "Dog", "Other"}