-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (26 loc) · 861 Bytes
/
app.py
File metadata and controls
33 lines (26 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from io import BytesIO
from fastapi import FastAPI, UploadFile, File
from PIL import Image
import numpy
from model.model import YOLOSeg
app = FastAPI(
title="Image object segmentation",
description="API to image object segmentation"
)
model = YOLOSeg(
'./data/yolov8s-seg.onnx',
conf_thres=0.15,
iou_thres=0.5
)
@app.post("/process_image")
async def predict(file: UploadFile = File(...)) -> dict:
"""
Process the uploaded image and return the result as a dictionary.
:param file: The uploaded image file.
:return: A dictionary containing the processed image and the predicted classes.
:rtype: dict
"""
image_bytes = await file.read()
image = numpy.asarray(Image.open(BytesIO(image_bytes)))
proc = model.model_run(image)
return {"processed_image": proc['img'].tolist(), 'classes': proc['resp']}