1
@app.post("/predict/")
async def predict(file:UploadFile = File(...)):
    bytes_str = io.BytesIO(await file.read())
    img = Image.open(bytes_str)
    img_array = np.array(img.convert('RGB'))
    img_array = cv2.resize(img_array, (1024,1024))
    img_final = np.expand_dims(img_array, axis = 0)
    pred = model.predict(img_final)

This code returns a NumPy array and I need to return it on FastAPI on an endpoint, but what could be the strategy?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    Does this answer your question? [How can I return a NumPy array using FastAPI?](https://stackoverflow.com/questions/71102658/how-can-i-return-a-numpy-array-using-fastapi) – aaossa Apr 08 '22 at 16:03

1 Answers1

0

Try a simple pred.tolist() to return a normal list that fastapi understands.

Hyn
  • 1
  • 1