Raspberry Pi AI Kit: Training Models with Google Colab

Raspberry Pi AI Kit: Training Models with Google Colab

Training the YOLOv8s Model

Data Training Using Google Colab

For users without access to a powerful GPU, Google Colab provides a free alternative for model training. This section explains how to use Google Colab to train your YOLOv8s model.

Step-by-Step Guide:

  1. Open Google Colab link and sign up:
  2. Connect GPU: Click the dropdown menu and choose GPU. Then run the check resource cell. If GPU is available you should seeing something similar on the image below.


  3. Install Required Libraries: This imports the ultralytics library and runs a series of checks to ensure its properly installed and configured.


     
  4. Export Dataset: This code uses the Roboflow API to download a specific version of your custom dataset in YOLOv8 format. Replace the placeholder values with your actual Roboflow API key, workspace, and project names.


     
  5. Train the Model: Use the YOLOv8s model for training, adjust the epochs, batch and image size accordingly. Be patient and wait for the training to finish. This command starts the YOLOv8 training process. It specifies the task (object detection), mode (training), pre-trained model to start from (yolov8s.pt), dataset configuration, number of epochs, batch size, image size, and enables plot generation.


     
  6. Model Validation: This command runs the validation process on the trained model, evaluating its performance on the validation set.

  7. Model Inference: This command uses the trained model to perform object detection on the test images, with a confidence threshold of 0.25, and saves the results.


     
  8. Result:This code finds the most recent prediction results and displays the first three images with detected objects.



     
  9. Export ONNX model: This code loads the best trained model and exports it to ONNX format, which is useful for deploying the model in various environments.


     
  10. Download ONNX model: This cell initiates a download of the exported ONNX model file, allowing you to save it locally.

On the next section, we will setup the environment to convert the ONNX file to HEF for the model to be able to run on the Raspberry Pi AI Kit.

Hardware Components

Raspberry Pi AI Kit-13 TOPS AI Power for Raspberry Pi 5 and Bundles Best Seller