Only one node

For starters, open 4 terminal windows.

In one of them, if not already started, start roscore:

roscore

In other terminal, start the receiver:

rosrun basic_receiver receiver_node.py

In the third one, start the inference node:

rosrun inference_manager inference_node.py -fn INFER_FUNCTION -mp MODEL_PATH -sr SOURCE

Where:

If there isn’t already a node sending images, you can start a sender:

rosrun basic_sender sender_node.py

Multiple nodes - ROS Launch

Using a ROS launch file is possible to run the inference node multiple times at the same time using namespaces - this allows to infer multiple models and/or multiple image sources at the same time.

Learn more about roslaunch here

Here is an example of a launch file to run YoloV5 and YolopV2 on images from the sender node

<launch>

<!-- ####################################################################### -->
<!-- ############################# Arguments ############################### -->
<!-- ####################################################################### -->

    <!-- Image sources -->
    <arg name="front_camera" default="/cameras/frontcamera"/>
    <!-- YolopV2 -->
    <arg name="fn_yolopv2" default="yolopv2_module"/>
    <arg name="mp_yolopv2" default="/home/gribeiro/catkin_ws/src/perception_with_multi-task_neural_networks/models/yolopv2.pt"/>
    <!-- YoloV5 -->
    <arg name="fn_yolov5_det" default="yolov5sDet_module"/>
    <arg name="mp_yolov5s_det" default="/home/gribeiro/catkin_ws/src/perception_with_multi-task_neural_networks/models/yolov5s.torchscript"/>

<!-- ####################################################################### -->
<!-- ############################### Nodes ################################# -->
<!-- ####################################################################### -->
    <node pkg="basic_sender" name="image_sender" type="sender_node.py"/>

    <group ns='frontcamera/yolopv2'>
        <node pkg="basic_receiver" name="image_plotter" type="receiver_node.py" output="screen"/>
        <node pkg="inference_manager" name="inference_node" type="inference_node.py" args="-fn $(arg fn_yolopv2) -mp $(arg mp_yolopv2) -sr $(arg front_camera)"/>
    </group>

    <group ns='frontcamera/yolov5'>
        <node pkg="basic_receiver" name="image_plotter" type="receiver_node.py" output="screen"/>
        <node pkg="inference_manager" name="inference_node" type="inference_node.py" output="screen" args="-fn $(arg fn_yolov5_det) -mp $(arg mp_yolov5s_det) -sr $(arg front_camera)"/>
    </group>

</launch>

As you can see, this example is divided in two parts. The first one are the arguments that will be used when calling the nodes and the second part is where the nodes are called.

To keep everything consistent and organized, I suggest to use namespaces in the format /CameraName/ModelName as you can see in the following example:

    <group ns='frontcamera/yolov5'>
        <node pkg="basic_receiver" name="image_plotter" type="receiver_node.py" output="screen"/>
        <node pkg="inference_manager" name="inference_node" type="inference_node.py" output="screen" args="-fn yolov5sDet_module -mp /home/gribeiro/catkin_ws/src/perception_with_multi-task_neural_networks/models/yolovgpu5s.torchscript -sr $(arg front_camera)"/>
    </group>

Note: The namespace is defined in the parameter ns='frontcamera/yolov5'>