Hello world
Quick Start Guide
Last updated
Quick Start Guide
Last updated
This guide walks you through the basics of working with your Robopipe device. You'll learn how to:
Capture images from a connected device
Label data for training an AI model
Build and deploy a simple neural network co classify objects as "black" or "other"
By the end you'll have a fully functioning AI model running directly on a Robopipe device.
The complete example with all the python code is available below. The jupyter notebook used for training the model and the model conversion is also available below.
In order to capture training data we need to specify camera and specific stream from which to capture images. To do this we will first list all cameras and streams.
Cameras will contain an array of connected cameras, containing their MXID along with other information. To find out more about cameras API head over to the API reference.
We will use the first camera.
We will also need to select a stream. Stream is either a single sensor on the camera or a combination of multiple sensors, usually used in detecting depth. To list all streams you can use the function below.
In my case, I will choose the first returned stream, which is CAM_A. CAM_A is usually the RGB camera on most cameras.
In order to train our model we first need to get the training data. These data will be RGB images captured by our device via out API. We will create a function that retrieves an image from the API and saves it to our defined location whenever we type 's' into the terminal. Visit other examples to see how to capture data automatically.
To capture data we simply call capture_data()
. This will, however, capture the data in full camera resolution, which might not be desired. In our case, the model will be trained on images of size 200x200. We can create another function, which will properly configure the camera, so that the captured images are the right size. There are numerous options which you can configure via the config and control APIs.
Capturing images in high resolution may require more processing power and storage. Use appropriate resolutions for your application.
We will use label studio for labeling.
Now head over to http://localhost:8080, create an account and create a new empty project. In the labeling setup tab, choose Image Classification, and enter red and other as choices. After you're done with the project configuration, click Save.
Now we can import our data. Click in "go to import" and select the folder in which you have saved the captured images and import selected images. Now click on "Label all tasks" and you can start labeling.
For each image, select either "black" or "other" and click on "submit".
After you are done with labeling, go back to the project overview, click on "export" and export your data as CSV. We will need this for the next step.
First, we will need some lilbraries. We build and train the model using PyTorch. We will use pandas and pillow for loading the data. All this will be done in jupyter notebook, you can use Visual Studio Code or any tool of your preference to view and edit the notebook. The notebook is available for download above in the description.
We will build a custom dataset class, which will load our images along with the label data form a specified location and use specified transformers to manipulate the data.
Next we will build and train the neural network itself. We create a class SimpleNN
. This network will only have 3 layers to keep things simple - input, output, and 1 hidden layer. For the activation function we will use RelU.
Now we can train the model, feel free to tweak the parameters to your liking.
When looking at the output, you should observe that the loss is getting smaller.
In order to be able to deploy the network on our device, we must first convert it to a suitable format. Luxonis uses MyriadX blob format. To see conversion guides for models built with frameworks other than PyTorch, please refer to Luxonis Conversion Guide.
This will save our model in the ONNX format into model.onnx
.
To finally obtain a file we can upload into our device we will use blobconverter. You can install it via pip.
To deploy out model we will use our API.
Calling this function will take a few seconds, since the camera needs to load the model and restart. After it is finished, we can finally observe the model working. For that we will create a simple websocket client, that connects to our API and receives data straight from our controller containing the output of the model.
Congratulations! You've successfully:
Captured and labeled data.
Trained a custom AI model.
Deployed it to a Robopipe device.
Explore our Examples Page for more advanced projects and ideas.