Skip to content

yolov8

This service will use Yolov8 to analyse the image content according to the selected model type:

  • detect: object detection
  • segment: object segmentation
  • pose: human pose estimation
  • classify: image classification

The API documentation is automatically generated by FastAPI using the OpenAPI standard. A user friendly interface provided by Swagger is available under the /docs route, where the endpoints of the service are described.

This simple service only has one route /compute that takes an image and the model type in text format as input, and the image will be analyzed according to the selected model type.

Environment variables

All environment variables are described in the .env file.

The environment variables can be overwritten during the CI/CD pipeline described in the yolov8.yml GitHub workflow file.

Start the service locally with Python

In the yolov8 directory, start the service with the following commands.

# Generate the virtual environment
python3 -m venv .venv

# Activate the virtual environment
source .venv/bin/activate

# Install the requirements
pip install \
    --requirement requirements.txt \
    --requirement requirements-all.txt

Start the application.

1
2
3
4
5
# Switch to the `src` directory
cd src

# Start the application
uvicorn --reload --port 9696 main:app

Access the service documentation on http://localhost:9696/docs.

Run the tests with Python

For each module a test file is available to check the correct behavior of the code. The tests are run using the pytest library with code coverage check. To run the tests, use the following command inside the yolov8 folder:

pytest --cov-report term:skip-covered --cov-report term-missing --cov=. -s --cov-config=.coveragerc

Start the service locally with minikube and the Docker image hosted on GitHub

Start the service with the following commands. This will start the service with the official Docker images that are hosted on GitHub.

In the yolov8 directory, start the service with the following commands.

1
2
3
4
5
# Start the yolov8 backend
kubectl apply \
    -f kubernetes/yolov8.config-map.yml \
    -f kubernetes/yolov8.stateful.yml \
    -f kubernetes/yolov8.service.yml

Create a tunnel to access the Kubernetes cluster from the local machine. The terminal in which the tunnel is created must stay open.

# Open a tunnel to the Kubernetes cluster
minikube tunnel --bind-address 127.0.0.1

Access the yolov8 documentation on http://localhost:9696/docs.

Access the Core Engine documentation on http://localhost:8080/docs to validate the backend has been successfully registered to the Core Engine.

Start the service locally with minikube and a local Docker image

Note: The service StatefulSet (yolov8.stateful.yml file) must be deleted and recreated every time a new Docker image is created.

Start the service with the following commands. This will start the service with the a local Docker image for the service.

In the yolov8 directory, build the Docker image with the following commands.

# Access the Minikube's Docker environment
eval $(minikube docker-env)

# Build the Docker image
docker build -t ghcr.io/swiss-ai-center/yolov8:latest .

# Exit the Minikube's Docker environment
eval $(minikube docker-env -u)

# Edit the `kubernetes/yolov8.stateful.yml` file to use the local image by uncommented the line `imagePullPolicy`
#
# From
#
#        # imagePullPolicy: Never
#
# To
#
#        imagePullPolicy: Never

In the yolov8 directory, start the service with the following commands.

1
2
3
4
5
# Start the yolov8 backend
kubectl apply \
    -f kubernetes/yolov8.config-map.yml \
    -f kubernetes/yolov8.stateful.yml \
    -f kubernetes/yolov8.service.yml

Create a tunnel to access the Kubernetes cluster from the local machine. The terminal in which the tunnel is created must stay open.

# Open a tunnel to the Kubernetes cluster
minikube tunnel --bind-address 127.0.0.1

Access the yolov8 documentation on http://localhost:9696/docs.

Access the Core Engine documentation on http://localhost:8080/docs to validate the backend has been successfully registered to the Core Engine.


Last update: November 9, 2023 08:50:15