FastAPI 微服务,基于 YOLOv8 识别图片中的校园常见失物并返回前三个标签。分类集合是从 COCO-80 精选并重命名的英文标签,聚焦校园场景。
当前默认的标签清单:
- backpack
- umbrella
- shoulder bag or wallet
- luggage or suitcase
- ball or sports gear
- water bottle or thermos
- tumbler
- cup
- laptop
- mouse
- presentation clicker or remote
- keyboard
- phone or tablet
- notebook or campus card
- watch or desk clock
- stationery (scissors-like)
- plush toy
- toiletry (toothbrush)
-
Create a virtual environment
python3 -m venv .venv source .venv/bin/activate -
Install dependencies
pip install -r requirements.txt
-
Download the YOLOv8s weights
mkdir -p models curl -L -o models/yolov8s.pt https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s.pt
-
Start the service
uvicorn main:app --host 0.0.0.0 --port 5101
You can also run
python main.pyto launch Uvicorn directly.
GET /health– Returns{ "status": "ok" }.POST /predict-category– Accepts a single image file and returns its top-3 labels.POST /predict-category-batch– Accepts 1–3 image files and returns the top-3 labels for each image.
All responses return the English COCO-80 labels alongside the normalised confidences.