From 9256b59ae1eb7a3b3516fc65e89a69c531c50d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=BF=94?= <18434361174@163.com> Date: Mon, 21 Nov 2022 02:28:22 +0000 Subject: [PATCH] update Assisted-driving/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘翔 <18434361174@163.com> --- Assisted-driving/README.md | 32 ++--- Assisted-driving/config/coco.names | 154 ++++++++++++------------ Assisted-driving/config/coco1.names | 80 ------------ Assisted-driving/main_detection_test.py | 17 ++- 4 files changed, 91 insertions(+), 192 deletions(-) delete mode 100644 Assisted-driving/config/coco1.names diff --git a/Assisted-driving/README.md b/Assisted-driving/README.md index 482e34a..e7a99d9 100644 --- a/Assisted-driving/README.md +++ b/Assisted-driving/README.md @@ -1,14 +1,7 @@ # MindXSDK 辅助驾驶 ## 1 简介 -本开发样例基于MindX SDK实现了车辆、交通指示牌分类、车道线检测,并可视化呈现, 主要实现两个功能: -> 实现交通道路的信号标志的检测和分类 -> 实现交通道路的车道线检测 - -其主要流程为: -- 交通信号检测:将底库图片调整大小为1216*1216分辨率,利用目标检测模型YOLOv3推理,检测图片中的各种交通信号标志,检测结果经过抠图与调整大小。 -- 交通信号识别:将底库图片调整大小为224*224分辨率,利用目标分类模型Resnet18推理,对检测的交通信号标志进行分类。 -- 车道线检测:将底库图片调整大小为446*446分辨率,利用目标分割模型U-net推理,对输入图像进行车道线的分割。 +本开发样例基于MindX SDK实现了车辆、交通指示牌分类、车道线检测,并可视化呈现。 ## 2 目录结构 本工程名称为Assisted-driving,工程目录如下图所示: @@ -79,14 +72,13 @@ ADAS |numpy | 1.22.4 | |opencv_python|4.6.0.66| -- 设置环境变量(请确认install_path路径是否正确) +- 设置环境变量 ``` #执行如下命令 . ${SDK-path}/set_env.sh . ${ascend_toolkit_path}/set_env.sh ``` - 请注意MindX SDK使用python版本为3.9.2,如出现无法找到python对应lib库请在root下安装python3.9开发库 ``` apt-get install libpython3.9 @@ -94,9 +86,6 @@ conda install -c conda-forge pycocotools ``` ## 4 模型转换 -辅助驾驶先采用了yolov3模型将图片中的交通标志检测出来,然后利用resnet18模型获对检测出来的交通标志进行分类;在道路线分割模型中使用u-net网络车道线分割检测。由于模型分别是基于Pytorch和Tensorflow的深度模型,我们需要借助ATC工具分别将其转换成对应的.om模型。 - -### 4.1 模型转换: **步骤1** 获取原始模型权重(.onnx和.om模型)  [模型下载](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/ascend_community_projects/Assisted_driving/model.zip) @@ -109,7 +98,7 @@ conda install -c conda-forge pycocotools > 模型转换使用了ATC工具,如需更多信息请参考:[ATC工具使用指南-快速入门](https://support.huaweicloud.com/tg-cannApplicationDev330/atlasatc_16_0005.html) -> car检测模型需要从此[链接](https://ascend-repo-modelzoo.obs.cn-east-2.myhuaweicloud.com/c-version/YoloV3_for_TensorFlow/zh/1.6/m/YOLOv3_TensorFlow_1.6_model.zip)进行下载,将 YOLOv3_TensorFlow_1.6_model\single\om中的yolov3_tf_aipp.om复制到model目录下。 +>车辆检测模型需要从此[链接](https://ascend-repo-modelzoo.obs.cn-east-2.myhuaweicloud.com/c-version/YoloV3_for_TensorFlow/zh/1.6/m/YOLOv3_TensorFlow_1.6_model.zip)进行下载,将 YOLOv3_TensorFlow_1.6_model\single\om中的yolov3_tf_aipp.om复制到model目录下。 ``` #进行模型转换 @@ -134,15 +123,8 @@ ATC run success, welcome to the next use. ### 5.1 数据 -> 本文将所使用到的数据集进行整理,将数据集下载后进行解压并放置到项目目录中,参考上述给出文件目录结构。[数据集 ](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/ascend_community_projects/Assisted_driving/data.zip)。从[数据集链接](https://pjreddie.com/projects/coco-mirror/)将coco2014验证集和标注文件下载,并解压到./data/car/目录下,具体格式请参考目录结构。 +> 本文将所使用到的数据集进行整理,将数据集下载后进行解压并放置到项目目录中,参考上述给出文件目录结构。[交通标志和车道线检测数据集 ](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/ascend_community_projects/Assisted_driving/data.zip)。从[车辆检测数据集](https://pjreddie.com/projects/coco-mirror/)将coco2014验证集和标注文件下载,并解压到./data/car/目录下,具体格式请参考目录结构。 -涉及文件夹 - -> “项目所在目录/data/detection/data”:用于存放Tinghua100K数据集的测试数据集,包含了该数据集的测试样例。 - -> “项目所在目录/data/detection/result”:用于存放待交通标志检测后的结果照片。 - -> “项目所在目录/data/detection/Tinghua100K_result_for_test.json”:用于存放待交通标志检测后的检测结果。 ### 5.2 适用场景 @@ -155,7 +137,7 @@ ATC run success, welcome to the next use. #功能测试 支持jpg,png格式图像 python3.9 main_deteciton.py --image_folder <测试图像文件夹路径> --save_image <测试图像结果保存路径> # python3.9 main_detection.py --image_folder ./test --save_image ./result -#执行完成后,其余结果保存在 result 件中。 +#执行完成后,结果保存在 result 件中。 #进行检测测试 @@ -187,14 +169,14 @@ mIou is : 0.3598664687463788 #参考精度为 mIou is : 0.3610 ``` -### 6.2 汽车检测 +### 6.2 车辆检测 ``` #功能测试 支持jpg,jpeg,PNG格式图像 python3.9 main_car.py --image_folder <测试图像文件夹路径> --res_dir_name <测试图像结果保存路径> # python3.9 main_car.py --image_folder ./test --res_dir_name ./result 执行完成后,在result文件夹,并保存有相应的结果照片。 -#进行汽车测试,测试使用的为数据集为config/coco2014_minival.txt,是参仓库生成的。 +#进行车辆测试,测试使用的数据集为config/coco2014_minival.txt,是参考仓库生成的。 python3.9 main_car_test.py python3.9 test_car.py diff --git a/Assisted-driving/config/coco.names b/Assisted-driving/config/coco.names index ca76c80..5e067f2 100644 --- a/Assisted-driving/config/coco.names +++ b/Assisted-driving/config/coco.names @@ -1,80 +1,80 @@ -person -bicycle +None +None car -motorbike -aeroplane +None +None bus -train +None truck -boat -traffic light -fire hydrant -stop sign -parking meter -bench -bird -cat -dog -horse -sheep -cow -elephant -bear -zebra -giraffe -backpack -umbrella -handbag -tie -suitcase -frisbee -skis -snowboard -sports ball -kite -baseball bat -baseball glove -skateboard -surfboard -tennis racket -bottle -wine glass -cup -fork -knife -spoon -bowl -banana -apple -sandwich -orange -broccoli -carrot -hot dog -pizza -donut -cake -chair -sofa -pottedplant -bed -diningtable -toilet -tvmonitor -laptop -mouse -remote -keyboard -cell phone -microwave -oven -toaster -sink -refrigerator -book -clock -vase -scissors -teddy bear -hair drier -toothbrush +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None +None \ No newline at end of file diff --git a/Assisted-driving/config/coco1.names b/Assisted-driving/config/coco1.names deleted file mode 100644 index 5e067f2..0000000 --- a/Assisted-driving/config/coco1.names +++ /dev/null @@ -1,80 +0,0 @@ -None -None -car -None -None -bus -None -truck -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None -None \ No newline at end of file diff --git a/Assisted-driving/main_detection_test.py b/Assisted-driving/main_detection_test.py index c362047..5f2ecae 100644 --- a/Assisted-driving/main_detection_test.py +++ b/Assisted-driving/main_detection_test.py @@ -427,7 +427,6 @@ if __name__ == '__main__': train_results = {"imgs": {}} for k, img_path in enumerate(Image_[:]): - try: img_id = img_path.split('/')[-1].split('.')[0] if os.path.exists(img_path) != 1: print("The test image does not exist.") @@ -509,7 +508,7 @@ if __name__ == '__main__': objects = [] img_copy = Image.open(img_path) detections = rescale_boxes(detections, opt.img_size, img_copy.size) - img_path_save = 'tmp.jpg' + IMGPATH = 'tmp.jpg' for i, (x1, y1, x2, y2, conf, cls_conf, cls_pred) in enumerate( detections): @@ -528,7 +527,7 @@ if __name__ == '__main__': w, h = crop_sign_org.size n = 32 // min(crop_sign_org.size) + 1 crop_sign_org = crop_sign_org.resize((w * n, h * n)) - crop_sign_org.save(img_path_save) + crop_sign_org.save(IMGPATH) time.sleep(0.05) if opt.draw: draw = ImageDraw.Draw(img_copy) # 在上面画画 @@ -537,11 +536,11 @@ if __name__ == '__main__': STREAMNAME = b'classication' INPLUGINLD = 0 - if os.path.exists(img_path_save) != 1: + if os.path.exists(IMGPATH) != 1: continue print("The test image does not exist.") - with open(img_path_save, 'rb') as f: + with open(IMGPATH, 'rb') as f: dataInput.data = f.read() unique_Id_tmp = streamManagerApi.SendData( STREAMNAME, INPLUGINLD, dataInput) @@ -567,17 +566,15 @@ if __name__ == '__main__': _2 = np.argmax(prediction) objects.append({'category': Class_Label.get(_2), 'score': 848.0, 'bbox': { 'xmin': x1, 'ymin': y1, 'ymax': y2, 'xmax': x2}}) - os.remove(img_path_save) + os.remove(IMGPATH) if opt.draw: - img_path_save = os.path.join( + IMGPATH = os.path.join( opt.save_image, str(img_id) + '.png') - img_copy.save(img_path_save) + img_copy.save(IMGPATH) try: train_results["imgs"][img_id] = {"objects": objects} except KeyError: print('error') - except: - pass FLAGS = os.O_WRONLY | os.O_CREAT | os.O_EXCL MOD = stat.S_IWUSR | stat.S_IRUSR