-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathml.py
More file actions
28 lines (24 loc) · 703 Bytes
/
Copy pathml.py
File metadata and controls
28 lines (24 loc) · 703 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
from ultralytics import YOLO
import numpy as np
from PIL import Image
import io
from fastapi import FastAPI,UploadFile
def load_model():
modelpath = "best.pt"
model = YOLO(modelpath)
return model
model = load_model()
app = FastAPI()
@app.post('/get_predictions')
async def get_predictions(file:UploadFile):
image = await file.read()
image = Image.open(io.BytesIO(image))
result = model(image)
names = result[0].names
probability = result[0].probs.data.numpy()
prediction = np.argmax(probability)
response = {
'Prediction':names[prediction],
'Confidence':float(probability[prediction])
}
return response