本科阶段最后一次竞赛Vlog——2024年智能车大赛智慧医疗组准备全过程——12使用YOLO-Bin

本科阶段最后一次竞赛Vlog——2024年智能车大赛智慧医疗组准备全过程——12使用YOLO-Bin

根据前面内容,所有的子任务已经基本结束,接下来就是调用转化的bin模型进行最后的逻辑控制了

1 .YOLO的bin使用

对于yolo其实有个简单的办法,也不需要自己写代码进行推理

直接找到websocker的demo修改配置文件

image-20241216150709943

配置文件在手册其实也是作为一个demo进行演示,下面我把配置文件内容也给大家,大家就不需要去翻手册了

但是下面内容要根据你实际情况修改类别和类别list里面的label

{
    "model_file": "/root/yolov5s_640x640.5.13.bin",
    "dnn_Parser": "yolov5",
    "model_output_count": 3,
    "class_num": 1,
    "cls_names_list": "/root/obstacles.list",
    "score_threshold": 0.65,
    "nms_threshold": 0.6,
    "nms_top_k": 2
}

2.模型数据的接受

既然使用了websocket那么如何拿到标签信息,经过当时在论坛上找来找去,然后改了改这里给大家提供个demo

大家可以根据自己的需要把需要得内容进行发布出去

import rclpy
from rclpy.node import Node
from std_msgs.msg import Float64
import numpy as np
from ai_msgs.msg import PerceptionTargets
import threading

class YOffsetsMaxPublisher(Node):

    def __init__(self):
        super().__init__('y_offsets_max_publisher')
        self.YoloV5Subscriber = self.create_subscription(
            PerceptionTargets,
            'hobot_dnn_detection',
            self.YoloV5_listener_callback,
            100)
        self.data_store = {
            "y_offsets_conf": 150,  # 示例值,根据实际情况调整
            "needzhuanwan": False
        }
        self.lock = threading.Lock()
        

    def YoloV5_listener_callback(self, msg):
        result_list = msg.targets 
        obj_len = len(result_list)
        self.obj_x = np.full(8, -1)  # 存坐标
        self.obj_y = np.full(8, -1)
        max_area = 0  # 用于存储最大面积
        with self.lock:
            for i in range(obj_len):
                if not result_list[i].rois:
                    continue
                for roi in result_list[i].rois:
                    box = roi.rect  # 直接获取 roi 的 rect 属性
                    x_offset = box.x_offset
                    y_offset = box.y_offset
                    width = box.width
                    height = box.height
                    area = width * height
                    id = result_list[i].track_id
                    

def main(args=None):
    rclpy.init(args=args)
    y_offsets_max_publisher = YOffsetsMaxPublisher()
    rclpy.spin(y_offsets_max_publisher)
    y_offsets_max_publisher.destroy_node()
    rclpy.shutdown()

if __name__ == '__main__':
    main()

3.总结

目前对于yolo的使用已经结束,其实有需要大家可以使用cpp和py单独使用dnn模块进行推理也可以

这里给大家带来小白用法,更多的用法大家可以去地瓜手册进行查询api函数

下面给大家带来resnet使用