Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from io import BytesIO

import numpy as np
Expand All @@ -22,11 +23,25 @@ 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):
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)
self.model = model #Déleguer à une autre classe | créer LoadModel

def execute(self, filepath:str|BytesIO):
img = load_image(filepath)
Expand Down
Binary file not shown.
11 changes: 6 additions & 5 deletions packages/mlopspython-inference/tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
from pathlib import Path
import pytest

from mlopspython_inference.inference_pillow import Inference
from mlopspython_inference.inference_pillow import Inference, ModelPillow, ModelMock

BASE_PATH = Path(__file__).resolve().parent
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 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"}
Expand Down
1 change: 1 addition & 0 deletions production/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ COPY packages/ packages/
COPY production/api/pyproject.toml production/api/pyproject.toml
COPY production/api/uv.lock production/api/uv.lock


WORKDIR /app/production/api
RUN uv venv && source .venv/bin/activate && uv sync --no-dev --frozen --no-editable

Expand Down
Loading