Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mbari-org/fastapi-localtrack
Lightweight Machine Learning API for running video tracking pipelines powered by the FastAPI framework
https://github.com/mbari-org/fastapi-localtrack
deepsea fastapi yolov5
Last synced: 12 days ago
JSON representation
Lightweight Machine Learning API for running video tracking pipelines powered by the FastAPI framework
- Host: GitHub
- URL: https://github.com/mbari-org/fastapi-localtrack
- Owner: mbari-org
- License: other
- Created: 2023-07-21T21:31:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-12T18:36:04.000Z (about 1 year ago)
- Last Synced: 2024-06-11T18:19:45.001Z (6 months ago)
- Topics: deepsea, fastapi, yolov5
- Language: Python
- Homepage:
- Size: 246 KB
- Stars: 1
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![MBARI](https://www.mbari.org/wp-content/uploads/2014/11/logo-mbari-3b.png)](http://www.mbari.org)
[![Python](https://img.shields.io/badge/language-Python-blue.svg)](https://www.python.org/downloads/)**fastapi-localtrack** code is a lightweight API to process video. It uses the Python web framework [FastAPI](https://fastapi.tiangolo.com/).
- 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# Requirements
For deployment, you will need:
- [Docker](https://docs.docker.com/get-docker/)
- [Docker Compose](https://docs.docker.com/compose/install/)For development, you will need:
- [Python >=3.10](https://www.python.org/downloads/)
- [Anaconda](https://www.anaconda.com/)
- [Docker](https://docs.docker.com/get-docker/)
- [Docker Compose](https://docs.docker.com/compose/install/)
# TODO
- [ ] Wire in daemon and pytest to github actions
- [ ] Standardize .names convention for local and cloud# Deployment
## Clone the repository
```shell
git clone https://github.com/mbari-org/fastapi-localtrack
cd fastapi-localtrack
```## Build and start the docker containers
```shell
./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**## Try it out
Open the browser to http://localhost:8000/docs to see the API documentation.
### Health Check
Check the health of the server by going to `http://localhost:8000/health`. You should see the following response:```json
{"status":"ok"}
```### See all jobs
Check the status of all jobs at `http://localhost:8000/status````json
{
"jobs": [
{
"id": 1,
"name": "yolov5s.pt V4361_20211006T162656Z_h265_10frame hawthorne standing",
"status": "QUEUED"
}
]
}
```### Process a video
```shell
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
```json
{
"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"
}
```### Model weights
YOLOv5 model weights in .pt files or contained in a tar.gz file as packaged in the
[deepsea-ai train](http://docs.mbari.org/deepsea-ai/commands/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
[minio](https://min.io/) 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](./bin/docker_run.sh).### Authentication
The credentials can be changed in the .env file. See [.env](.env) for details.
### NotificationTo setup the receiving notification service add the NOTIFY_URL to the [.env](.env) file.
The results will be available in the minio server if the notification service goes down.