簡體   English   中英

如何在 FastAPI 中返回 NumPy 數組?

[英]How can I return a NumPy array in FastAPI?

@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)

此代碼返回一個 NumPy 數組,我需要在端點上的 FastAPI 上返回它,但策略是什么?

嘗試一個簡單的 pred.tolist() 來返回一個 fastapi 理解的普通列表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM