การบันทึกเวลาในการโหลดโมเดล
คุณกำลังสร้างแอป FastAPI สำหรับจำแนกประเภทเพนกวิน และต้องการวัดเวลาที่ใช้ในการโหลดโมเดล พร้อมบันทึกค่าดังกล่าวลงใน log
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การ Deploy AI สู่ Production ด้วย FastAPI
คำแนะนำการฝึกหัด
- โหลด error logger ของ
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()