記錄載入模型所花費的時間
你正在建立一個用於分類企鵝的 FastAPI 應用程式,並想要量測載入模型所需的時間,然後將其寫入日誌。
本練習屬於課程
使用 FastAPI 將 AI 佈署到生產環境
練習說明
- 載入
uvicorn的錯誤記錄器。 - 以 INFO 等級記錄載入模型的處理時間。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from fastapi import FastAPI
import logging
import joblib
import time
# Get the uvicorn error logger
logger = logging.getLogger('____')
start_time = time.perf_counter()
model = joblib.load('penguin_classifier.pkl')
process_time = time.perf_counter() - start_time
# Log the process time at the INFO level
logger.____(f"Process time was {____} seconds.")
app = FastAPI()