fastapi-localtrack code is a lightweight API to process video. It uses the Python web framework FastAPI.
- New videos queued to process are handled by a daemon that scans for new videos every 15 seconds
- New models are scanned for every minute and uploaded to minio where they are available for processing
- Currently only YOLOv5 models are supported
For deployment, you will need:
For development, you will need:
- Wire in daemon and pytest to github actions
- Standardize .names convention for local and cloud
git clone https://github.com/mbari-org/fastapi-localtrack
cd fastapi-localtrack
./bin/docker_build.sh
./bin/run_prod.sh
Your server is now running at http://localhost:8000/docs
Data is stored in the minio server at http://localhost:9000
You can access the minio server at http://localhost:9000. The default credentials are:
- Access Key: localtrack
- Secret Key: ReplaceMePassword
Open the browser to http://localhost:8000/docs to see the API documentation.
Check the health of the server by going to http://localhost:8000/health
. You should see the following response:
{"status":"ok"}
Check the status of all jobs at http://localhost:8000/status
{
"jobs": [
{
"id": 1,
"name": "yolov5s.pt V4361_20211006T162656Z_h265_10frame hawthorne standing",
"status": "QUEUED"
}
]
}
curl -X 'POST' \
'http://localhost:8000/predict' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"model": "MegadetectorTest.pt",
"video": "http://localhost:8090/video/V4361_20211006T162656Z_h265_10frame.mp4",
"metadata": {},
"args": "--conf-thres=0.01 --iou-thres=0.4 --max-det=100 --agnostic-nms --imgsz 640"
}'
This should return a job id which can be used to retrieve the results or inspect the status
{
"message": "http://localhost:8090/video/V4361_20211006T162656Z_h265_10frame.mp4 queued for processing",
"job_id": 22,
"job_name": "MegadetectorTest.pt V4361_20211006T162656Z_h265_10frame hawthorne jumping"
}
YOLOv5 model weights in .pt files or contained in a tar.gz file as packaged in the deepsea-ai train command are currently supported. The assumption is that each .pt or .tar.gz file is unique as it is used to create a key that is used for training the model.
minio is an open source S3 compatible object store. It is used to store models, track configuration files and track results from processing video. It needs to be running to use the API and is started automatically when you run the ./bin/run_prod.sh.
The credentials can be changed in the .env file. See .env for details.
To setup the receiving notification service add the NOTIFY_URL to the .env file. The results will be available in the minio server if the notification service goes down.