Pythia is a web service for generating predictions of what is seen in an image using yolo and a custom model. It provides a simple web UI and a REST API for making predictions. The web UI is provided by CVisionAI. Swagger docs will be at http://hostname:8080/q/swagger-ui
. Health checks at http://hostname:8080/q/health
First, convert your yolov5/v8 model to torchscript. If you have a .pt
file you can convert it to torchscript using ultralytics:
# First install ultralytics!!
yolo export model=my-yolo-model.pt format=torchscript imgsz=640
# This will create my-yolo-model.torchscript files
To launch pythia, you will need the torchscript model and the names file that was used to create the pt model. Note that image requires internet access in order to fetch the native libraries for the host platform when needed.
docker run -d \
--name=pythia \
--restart=always \
-p 8080:8080 \
-v /path/to/models/:/opt/models \
mbari/pythia \
run /opt/models/my-yolo-model.torchscript /opt/models/my-yolo-model.names
# start server
quarkus dev -Dquarkus.args="src/test/resources/models/mbari-mb-benthic-33k.torchscript src/test/resources/models/mbari-mb-benthic-33k.names"
# Send a request
curl -X POST 'http://localhost:8080/predict/' \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "file=@src/test/resources/images/03_00_51_14.jpg;type=image/jpg"
The model used in development is from the FathomNet ModelZoo.
Pythia depends on native libraries. These platform specific libraries can be downloaded at runtime or they can be included at build time via maven profiles.
mvn help:active-profiles -P linux-arm -P -macos-arm
The following profiles are active:
- linux-arm (source: org.mbari:pythia:1.0.0-SNAPSHOT)
vs.
mvn help:active-profiles -P linux-arm
The following profiles are active:
- linux-arm (source: org.mbari:pythia:1.0.0-SNAPSHOT)
- macos-arm (source: org.mbari:pythia:1.0.0-SNAPSHOT)```
## Quarkus Stuff
This project uses Quarkus, the Supersonic Subatomic Java Framework.
If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .
## Running the application in dev mode
You can run your application in dev mode that enables live coding using:
```shell script
./mvnw compile quarkus:dev -Dquarkus.args="src/test/resources/models/mbari-mb-benthic-33k.torchscript src/test/resources/models/mbari-mb-benthic-33k.names"
NOTE: Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
The application can be packaged using:
./mvnw package
It produces the quarkus-run.jar
file in the target/quarkus-app/
directory.
Be aware that it’s not an über-jar as the dependencies are copied into the target/quarkus-app/lib/
directory.
The application is now runnable using java -jar target/quarkus-app/quarkus-run.jar
.
If you want to build an über-jar, execute the following command:
./mvnw package -Dquarkus.package.type=uber-jar
The application, packaged as an über-jar, is now runnable using java -jar target/*-runner.jar
.
You can create a native executable using:
./mvnw package -Pnative
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
./mvnw package -Pnative -Dquarkus.native.container-build=true
You can then execute your native executable with: ./target/pixel-prophet-1.0.0-SNAPSHOT-runner
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.
Easily start your Reactive RESTful Web Services