# TrafficSignDetection **Repository Path**: ai_wei_zhi_tu/TrafficSignDetection ## Basic Information - **Project Name**: TrafficSignDetection - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-04-29 - **Last Updated**: 2025-04-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 基于 AIWay Edge 开源硬件实现交通路标检测 ## 1 模型下载 ### 1.1 下载预训练模型 ```bash cd /path/to/TrafficSignDetection wget https://gitee.com/ai_wei_zhi_tu/TrafficSignDetection/releases/download/v0.0.0/best_model.zip unzip best_model.zip ``` ### 1.2 自行训练模型 在代码仓库中我们已经提交了我们训练好的模型,如果你需要自行训练模型,请前往 [百度飞桨星河社区《基于 AIWay Edge 开源硬件实现交通路标检测》](https://aistudio.baidu.com/project/edit/9077903) 按照流程执行训练并将 **best_model.zip** 压缩包下载到本地。然后执行以下代码: ```bash cd /path/to/TrafficSignDetection unzip best_model.zip ``` ## 2 模型部署 ```python # 导入必要的库 import swift_deploy # 用于模型部署和推理的自定义库 import cv2 # OpenCV库,用于图像处理 # 主程序入口 if __name__ == "__main__": # 初始化目标检测模型(支持两种后端) # 如果使用 NCNN 后端(当前被注释) det_model = swift_deploy.PaddleDet( "./best_model/best_model.ncnn.bin", "./best_model/best_model.ncnn.param" ) # 当前使用的 RKNN 后端(瑞芯微芯片专用格式) # det_model = swift_deploy.PaddleDet("./best_model/best_model.rknn") # 初始化模型(必须在使用前调用) bgr2rgb = True # 用 OpenCV 读取图像的时候,需要将 BGR 转换为 RGB; 如果使用 FFMPEG 读取,则 bgr2rgb = False det_model.set_resize(416, 416, bgr2rgb) # For picodet_shufflenetv2_1x_416_coco det_model.initialize() # 待测试的图片路径列表 image_path_list = [ "./images/road0.png", # 测试图0 "./images/road10.png", # 测试图1 "./images/road1.png", # 测试图2 "./images/road100.png", # 测试图3 ] label_list = ["speedlimit", "crosswalk", "trafficlight", "stop"] # 遍历所有测试图片 for image_path in image_path_list: # 使用OpenCV读取图片 image = cv2.imread(image_path) if image is None: print(f"Failed to read {image_path}") continue # 使用模型进行预测 results = det_model.predict(image) # 打印预测结果(格式:图片路径: 预测标签, 置信度分数) for result in results: print(f"{image_path}: {result.box} {label_list[result.label_id]}, {result.score}") out_image = swift_deploy.visualize_detection(image, results) cv2.imwrite(f"result_image.png", out_image) ``` ## 3 代码运行结果 ```text [INFO] SwiftDeploy Version: 0.1.5 ./images/road10.png: [132 x 234 from (107, 22)] trafficlight, 0.50830078125 ./images/road1.png: [129 x 239 from (138, 57)] trafficlight, 0.6689453125 ./images/road100.png: [293 x 315 from (42, 16)] speedlimit, 0.69921875 ./images/road100.png: [124 x 138 from (204, 92)] speedlimit, 0.55810546875 ```