-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4be4844
commit 6076c36
Showing
4 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[tool.ruff] | ||
line-length = 120 | ||
target-version = "py311" | ||
|
||
[tool.ruff.lint] | ||
select = [ | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import bentoml | ||
import numpy as np | ||
from onnxruntime import InferenceSession | ||
|
||
if TYPE_CHECKING: | ||
from PIL import Image | ||
|
||
|
||
@bentoml.service( | ||
resources={"cpu": "2"}, | ||
traffic={"timeout": 10}, | ||
) | ||
class ImageClassifierService: | ||
"""Image classifier service using ONNX model.""" | ||
|
||
def __init__(self) -> None: | ||
self.model = InferenceSession("model.onnx") | ||
|
||
@bentoml.api | ||
def predict(self, image: Image.Image) -> list[float]: | ||
"""Predict the class of the input image.""" | ||
input_data = np.array(image).astype(np.float32) | ||
output = self.model.run(None, {"input": input_data}) | ||
return output[0].tolist() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters