Member-only story

Deploy YoloV8 ONNX

Ali Mustofa
5 min readFeb 23, 2023

Deploying a machine learning (ML) model is to make it available for use in a production environment. This means that the ML model is integrated into a larger software application, a web service, or a system that can take inputs, process them using the model, and return the model’s output as a response.

FastAPI is a modern, fast, and lightweight Python web framework for building APIs (Application Programming Interfaces). FastAPI is built on top of the Starlette ASGI (Asynchronous Server Gateway Interface) framework and uses the Pydantic library for data validation and serialization.

How to Deploy?

Install requirements

pip install numpy, opencv-python, pillow
pip install fastapi
pip install "uvicorn[standard]"

Import library

import io
from typing import List, Tuple
import cv2
import numpy as np
import uvicorn
from fastapi import FastAPI, File
from numpy import ndarray
from PIL import Image

Create detection class

class Detection:
def __init__(self,
model_path: str,
classes: List[str]
):
self.model_path = model_path
self.classes = classes
self.model = self.__load_model()

def __load_model(self) -> cv2.dnn_Net:
net = cv2.dnn.readNet(self.model_path)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA_FP16)…

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

No responses yet

Write a response