-
Notifications
You must be signed in to change notification settings - Fork 2
Add onnx serving #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add onnx serving #123
Conversation
|
|
||
| EXPOSE 8000 | ||
|
|
||
| CMD ["sh", "-c", "PYTHONPATH=/app/src uvicorn onnx_server:app --reload --host 0.0.0.0 --port 8000"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| CMD ["sh", "-c", "PYTHONPATH=/app/src uvicorn onnx_server:app --reload --host 0.0.0.0 --port 8000"] | |
| ENV PYTHONPATH=/app/src | |
| ENTRYPOINT ["uvicorn"] | |
| CMD ["onnx_server:app", "--reload", "--host", "0.0.0.0", "--port", "8000"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu peux virer ce fichier si on a un pyproject.toml
|
|
||
| import logging | ||
| from typing import Any, AnyStr, Dict, List, Union | ||
| import numpy as np | ||
| from fastapi import APIRouter, HTTPException, Request | ||
| import onnxruntime as ort | ||
| import time | ||
| import os | ||
| from PIL import Image | ||
| from pathlib import Path | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| from utils.yolo11n_postprocessing import ( | ||
| compute_severities, | ||
| non_max_suppression, | ||
| yolo_extract_boxes_information, | ||
| compute_iou, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exécute le linter pour respecter la pep8 stp
|
|
||
| # Lister les modèles ONNX chargés | ||
| @api_router.get("/models") | ||
| async def get_models(request: Request): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tu peux ajouter du type hint pour le retour stp
|
|
||
| # Récupérer les métadonnées d’un modèle | ||
| @api_router.get("/models/{model_name}/versions/{model_version}/resolution") | ||
| async def get_model_metadata(model_name: str, model_version: str, request: Request): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pareil le type hint de retour stp
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
faudrait que tu appliques un linter pour éviter toutes ces lignes inutiles -> regarde là
| lint: |
| os.environ["MODELS_PATH"] = "../models" | ||
|
|
||
| # sys.path.append() ajoute src/ aux chemins où Python cherche les modules. | ||
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../src"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pourquoi on a besoin de faire ça ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ligne 11 : Car ce code configure une variable d'environnement qui indique où trouver les modèles ONNX
Le serveur utilise cette variable pour savoir où chercher les modèles à charger
ligne 14 : car elle ajoute le dossier src au PYTHONPATH, c'est nécessaire car le fichier de test est dans le dossier tests et a besoin d'importer des modules du dossier src.
Sans cette ligne, Python ne pourrait pas trouver le module onnx_server car il n'est pas dans le chemin de recherche par défaut. C'est pourquoi cet ajout doit être fait avant l'import from onnx_server import app
|
|
||
|
|
||
| # Créer un client de test | ||
| client = TestClient(app) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
à mettre dans une fixture aussi stp
| def test_homepage(self): | ||
| """Test de la page d'accueil""" | ||
| response = client.get("/") | ||
| assert response.status_code == 200 | ||
| assert "Welcome to the onnx-server" in response.text | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pour les tests tu peux respecter la structure suivante stp :
# Given# When# Then
| image = Image.open(image_path).convert("RGB") | ||
| image = image.resize((640, 640)) | ||
| image_array = np.array(image).astype(np.float32) / 255.0 | ||
| image_array = np.transpose(image_array, (2, 0, 1)) | ||
| image_array = np.expand_dims(image_array, axis=0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pourquoi a-t-on besoin de faire tout ça ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Car ces traitement sur l'image sont nécessaires pour la préparer au format attendu par le modèle YOLO, sinon le modèle ne pourra pas lire l'image
No description provided.