Welcome to RDK S600 Developer Kit repository
4. Image Classification(mobilenetv2)
MobileNetV2 Image Classification
1.Function Introduction
The mobilenetv2 image classification algorithm example uses images as input, performs algorithm inference using the BPU, and publishes algorithm messages containing object categories.
The mobilenetv2 is a caffe model trained on the ImageNet data dataset. Model source: https://github.com/shicai/MobileNet-Caffe. The supported target types include people, animals, fruits, vehicles and other 1000 categories. For the specific supported categories, refer to the file /opt/tros/${TROS_DISTRO}/lib/dnn_node_example/config/imagenet.list on the RDK (TogetheROS.Bot installed).
Code repository: https://github.com/D-Robotics/hobot_dnn
Application scenarios: mobilenetv2 is capable of predicting the category of a given image, and can be used for tasks such as digit recognition and object recognition. It is mainly applied in fields such as text recognition and image retrieval.
Food type identification case: https://github.com/frotms/Chinese-and-Western-Food-Classification
Supported Platforms
2.Preparation
The Ubuntu 20.04/Ubuntu 22.04/Ubuntu 24.04 system image has been flashed onto the RDK.
The tros.b has been successfully installed on the RDK.
A MIPI or USB camera has been installed on the RDK. If no camera is available, the algorithm effects can be experienced by replaying local JPEG/PNG images or MP4, H.264 and H.265 videos.
Ensure that the PC can access the RDK through the network.
3.User Guide
3.1 Using a MIPI camera
The mobilenetv2 image classification example subscribes to the images published by the sensor package, publishes an algorithm msg after inference, and displays the published images and the corresponding algorithm results on the PC browser through the websocket package.
Enable MIPI camera node
# Configure the tros.b environmentsource /opt/tros/setup.bashx# Configure the MIPI cameraexport CAM_TYPE=mipi
# Start the launch fileros2 launch dnn_node_example dnn_node_example.launch.py dnn_example_config_file:=config/mobilenetv2workconfig.json dnn_example_image_width:=480 dnn_example_image_height:=272If the MIPI camera cannot be detected, try the following commands:
xxxxxxxxxxdevmem 0x33805070 32 0x00000033devmem 0x33805074 32 0x00000033devmem 0x33805078 32 0x00000033devmem 0x3380507c 32 0x00000033Output Results
The terminal output during execution shows the following information:
xxxxxxxxxx[example-3] [WARN] [1655095481.707875587] [example]: Create ai msg publisher with topic_name: hobot_dnn_detection[example-3] [WARN] [1655095481.707983957] [example]: Create img hbmem_subscription with topic_name: /hbmem_img[example-3] [WARN] [1655095482.985732162] [img_sub]: Sub img fps 31.07[example-3] [WARN] [1655095482.992031931] [example]: Smart fps 31.31[example-3] [WARN] [1655095484.018818843] [img_sub]: Sub img fps 30.04[example-3] [WARN] [1655095484.025123362] [example]: Smart fps 30.04[example-3] [WARN] [1655095485.051988567] [img_sub]: Sub img fps 30.01[example-3] [WARN] [1655095486.057854228] [example]: Smart fps 30.07The log shows that the topic for publishing the algorithm inference results is hobot_dnn_detection, and the topic for subscribing to images is /hbmem_img.
Enter http://IP:8000 in the browser on the PC to view the image and the algorithm rendering effect (where IP is the IP address of the RDK):

3.2 Using a USB camera
The mobilenetv2 image classification example subscribes to the images published by the sensor package, publishes an algorithm msg after inference, and displays the published images and the corresponding algorithm results on the PC browser through the websocket package.
Enable USB camera node
xxxxxxxxxx# Configure the tros.b environmentsource /opt/tros/jazzy/setup.bashxxxxxxxxxx# Configure the USB cameraexport CAM_TYPE=usb
# Start the launch fileros2 launch dnn_node_example dnn_node_example.launch.py dnn_example_config_file:=config/mobilenetv2workconfig.json dnn_example_image_width:=1280 dnn_example_image_height:=720Output Results
The terminal output during execution shows the following information:
xxxxxxxxxx[example-3] [WARN] [1655095481.707875587] [example]: Create ai msg publisher with topic_name: hobot_dnn_detection[example-3] [WARN] [1655095481.707983957] [example]: Create img hbmem_subscription with topic_name: /hbmem_img[example-3] [WARN] [1655095482.985732162] [img_sub]: Sub img fps 31.07[example-3] [WARN] [1655095482.992031931] [example]: Smart fps 31.31[example-3] [WARN] [1655095484.018818843] [img_sub]: Sub img fps 30.04[example-3] [WARN] [1655095484.025123362] [example]: Smart fps 30.04[example-3] [WARN] [1655095485.051988567] [img_sub]: Sub img fps 30.01[example-3] [WARN] [1655095486.057854228] [example]: Smart fps 30.07Refer to the terminal output list to select different video resolutions. Note that higher resolutions may reduce the frame rate and cause video stuttering.
The log shows that the topic for publishing the algorithm inference results is hobot_dnn_detection, and the topic for subscribing to images is /hbmem_img.
Enter http://IP:8000 in the browser on the PC to view the image and the algorithm rendering effect (where IP is the IP address of the RDK):

3.3 Local image replay
The mobilenetv2 image classification algorithm example replays local JPEG/PNG images. After inference, the images rendered with the algorithm results are stored in the local running path.
Run the replay node
xxxxxxxxxx# Configure the tros.b environmentsource /opt/tros/jazzy/setup.bashxxxxxxxxxx# Start the launch fileros2 launch dnn_node_example dnn_node_example_feedback.launch.py dnn_example_config_file:=config/mobilenetv2workconfig.json dnn_example_image:=config/target_class.jpgReplay results
The terminal output during execution shows the following information:
xxxxxxxxxx[example-1] [INFO] [1654767648.897132079] [example]: The model input width is 224 and height is 224[example-1] [INFO] [1654767648.897180241] [example]: Dnn node feed with local image: config/target_class.jpg[example-1] [INFO] [1654767648.935638968] [example]: task_num: 2[example-1] [INFO] [1654767648.946566665] [example]: Output from image_name: config/target_class.jpg, frame_id: feedback, stamp: 0.0[example-1] [INFO] [1654767648.946671029] [ClassificationPostProcess]: outputs size: 1[example-1] [INFO] [1654767648.946718774] [ClassificationPostProcess]: out cls size: 1[example-1] [INFO] [1654767648.946773602] [ClassificationPostProcess]: class type:window-shade, score:0.776356[example-1] [INFO] [1654767648.947251721] [ImageUtils]: target size: 1[example-1] [INFO] [1654767648.947342212] [ImageUtils]: target type: window-shade, rois.size: 1[example-1] [INFO] [1654767648.947381666] [ImageUtils]: roi.type: , x_offset: 112 y_offset: 112 width: 0 height: 0[example-1] [WARN] [1654767648.947563731] [ImageUtils]: Draw result to file: render_feedback_0_0.jpegThe log shows that the algorithm infers that the image config/target_class.jpg is classified as a window-shade with a confidence score of 0.776356 (the algorithm only outputs the highest confidence classification result). The rendered image is stored with the file name render_feedback_0_0.jpeg, and the rendered image looks like this:
