YOLO와 BERT 모델을 함께 서빙하는 FastAPI 프로젝트입니다.
ppopgipang-ml/
├── app/
│ ├── __init__.py
│ ├── main.py
│ ├── core/
│ │ ├── __init__.py
│ │ ├── config.py
│ │ └── containers.py
│ ├── models/
│ │ ├── __init__.py
│ │ ├── yolo_model.py
│ │ └── bert_model.py
│ ├── services/
│ │ ├── __init__.py
│ │ ├── vision_service.py
│ │ └── bert_service.py
│ └── api/
│ ├── __init__.py
│ ├── dto/
│ │ ├── __init__.py
│ │ ├── detect_request.py
│ │ ├── detect_response.py
│ │ └── bert_response.py
│ └── controllers/
│ ├── __init__.py
│ ├── vision_controller.py
│ └── bert_controller.py
├── models/
│ ├── yolo_best.pt
│ └── bert-finetuned/
│ ├── config.json
│ ├── model.safetensors
│ ├── vocab.txt
│ ├── tokenizer_config.json
│ ├── tokenizer.json
│ └── special_tokens_map.json
├── .env
├── .gitignore
├── requirements.txt
└── README.md
- 가상환경 생성 및 활성화
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate- 의존성 설치
pip install -r requirements.txt- 모델 파일 준비
models/yolo_best.pt파일 배치models/bert-finetuned/디렉토리에 BERT 파일들 배치
- 서버 실행
uvicorn app.main:app --reload또는
python -m app.main.env 파일을 생성하여 경로와 라벨 정보를 설정합니다.
PROJECT_NAME=ppopgipang-ml
API_V1_STR=/api/v1
# YOLO 모델
YOLO_MODEL_PATH=models/yolo_best.pt
# BERT 모델
BERT_MODEL_PATH=models/bert-finetuned
NUM_LABELS=3curl -X POST "http://localhost:8000/api/v1/vision/detect" \
-H "Content-Type: multipart/form-data" \
-F "image=@test_image.jpg"curl -X POST "http://localhost:8000/api/v1/bert/classify" \
-H "Content-Type: application/json" \
-d '{"text": "테스트 텍스트입니다"}'curl -X POST "http://localhost:8000/api/v1/bert/classify/batch" \
-H "Content-Type: application/json" \
-d '{
"texts": [
"첫 번째 텍스트",
"두 번째 텍스트",
"세 번째 텍스트"
]
}'- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc