Behavior Metrics tutorial using Tensoflow
In this tutorial, you will train your first follow line brain for the F1 that can be run on Behavior Metrics.
Table of Contents
Prerequisites
First of all, make sure you have Behavior Metrics installed, following the installation section. You can try running the brain_f1_explicit that is already included on Behavior Metrics brains folder. This brain is capable of finishing every circuit available for the project.
Brain Class
There are three main functions that can be used to for performing I/O operations on the robot. You can also find a dummy file, with all the instructions, that you can use as a template for deployment.
Update Frame
Update the information to be shown in one of the GUI’s frames.
Arguments:
- frame_id {str} – Id of the frame that will represent the data
- data {*} – Data to be shown in the frame. Depending on the type of frame (rgbimage, laser, pose3d, etc)
def update_frame(self, frame_id, data):
Update Pose
Update the pose 3D information obtained from the robot.
Arguments:
- data {*} – Data to be updated, will be retrieved later by the UI.
def update_pose(self, pose_data):
Execute
Main loop of the brain. This will be called iteratively each TIME_CYCLE
def execute(self):
Training a Brain
All the deep learning brains with their code can be located at Deep Learning Studio’s repo. For this tutorial, we will be using PilotNet architecture, a CNN based solution for self-driving cars. You can navigate to the previous repo to the Formula 1-Follow line folder, where both implementations for pytorch and tensorflow are located. We will use tensorflow .
-
Follow the steps on that repo for generating a new deep learning model using tensorflow and PilotNet. On that repo you will find information about how to download the dataset and how to train the model. Using the examples shown there should be fine for this tutorial (you can explore different combinations afterwards 😄).
-
After training your first tensorflow model for the follow line problem, you will have a .h5 file generated by the previous execution.
-
Take that .h5 file and store it on behavior_metrics/models/ creating a new folder tensorflow_models.
-
We’re almost ready to go. Modify the DL-tensorflow.yml file under behavior_metrics/configs/ folder, changing the Model: ‘[your_model_name].h5’ with your model name.
-
Execute Behavior Studio with the command.
python3 driver_gazebo.py -c configs/default.yml -g
and your done. Press the PLAY button shown on the GUI and the f1 should be running!
NOTE: If you find any problem running this tutorial, create an issue on Behavior Metrics repo so we can help you.