-
【任务背景】近年来,随着人工智能和传感器技术的快速进步,自动驾驶汽车技术也取得了长足发展。从最初的辅助驾驶系统到如今可实现完全自主驾驶的汽车,自动驾驶技术正在改变我们的出行方式。其中,交通信号识别技术作为自动驾驶系统的核心功能之一,能够准确感知和识别道路上的各类交通标志、信号灯等,为车辆提供精准的行驶决策依据,确保行车安全性和效率。基于视觉的交通信号标志检测与识别任务旨在开发出精准高效的识别算法,助力自动驾驶汽车技术的进步。任务包含步行、非机动车行驶、环岛行驶、机动车行驶等多种交通信号标志类别,开发者会利用到计算机视觉领域的目标检测、关键点检测、图像分类等基础技术,为提升识别效率,也可以拓展使用剪枝、量化、蒸馏等模型方面的优化技术。ModelArts云平台提供任务相关的数据处理、模型训练、应用部署等技术文档及学习课程材料,助力开发者学习相关技术,了解实践操作。【数据说明】本次任务需要识别以下16种类别的交通标识,类别编号与定义如下表:i1i2i3i4Walk步行Non_motorized vehicles非机动车行驶Round the island 环岛行驶Motor vehicle 机动车行驶i5i6i7i8Keep on the right side of the road靠右侧道路行驶Keep on the left side of the road 靠左侧道路行驶Drive straight and turn right at the grade separation 立体交叉直行和右转弯行驶Drive straight and turn left 立体交叉直行和左转弯行驶i9i10i11i12Honk 鸣喇叭Turn right 向右转弯Turn left and right 向左向右转弯Turn left 向左转弯i13i14i15il50One way, straight 直行Go straight and turn right 直行和向右转弯Go straight and turn left 直行和向左转弯Minimum Speed Limit 最低限速50【任务说明】本任务的测试集为200张图片,这些图片为中国多个城市街景的高分辨率图像,每张图片包含1种交通信号标识。数据集图片示例检测结果以图片为单位输出其中包括交通信号标识的类别、坐标与置信度,每张图片输出一个结果,格式为json字符串,字段说明如下: { "detection_classes": ["i1"], "detection_boxes": [[576, 423, 669, 967]], "detection_scores": [0.4796633720397949] }• detection_classes:指图片中目标的类别,参见上面的数据说明。• detection_boxes:指图片中目标位置的水平矩形框坐标,坐标表示为[ymin,xmin,ymax,xmax]。• detection_scores:指检测结果的置信度。【案例教学】【准备数据集】# 步骤1:从OBS迁移数据集 import moxing as mox mox.file.copy_parallel("obs://trafficbuckets/dataset/update_traffic_sign.zip", "/home/ma-user/work/dataset/update_traffic_sign.zip") # 形参:源文件->指定位置# 步骤2:解压数据集并更改名称为update_traffic_sign import os os.system('unzip /home/ma-user/work/download/update_traffic_sign.zip -d /home/ma-user/work/dataset') os.system('mv /home/ma-user/work/dataset/"update traffic sign" /home/ma-user/work/dataset/update_traffic_sign')# 生成train和val图片名文本文件 from glob import glob import random # hyper parameter train_pic_rate = 0.7 # you can change! # 该目录存储图片数据 patch_fn_list = glob('/home/ma-user/work/dataset/update_traffic_sign/images/*.jpg') # you can change! # 返回存储图片名的列表,不包含图片的后缀 patch_fn_list = [fn for fn in patch_fn_list] # 将图片打乱顺序 random.shuffle(patch_fn_list) # 按照7:3比例划分train和val train_num = int(train_pic_rate * len(patch_fn_list)) train_patch_list = patch_fn_list[:train_num] valid_patch_list = patch_fn_list[train_num:] # produce train/valid/trainval txt file split = ['train', 'val', 'trainval'] # produce train/valid/trainval txt file split = ['train2017', 'val2017', 'trainval2017'] for s in split: # 存储文本文件的地址 save_path = '/home/ma-user/work/dataset/update_traffic_sign/' + s + '.txt' # you can change! if s == 'train2017': with open(save_path, 'w') as f: for fn in train_patch_list: # 将训练图像的地址写入train.txt文件 f.write('%s\n' % fn) elif s == 'val2017': with open(save_path, 'w') as f: for fn in valid_patch_list: # 将验证图像的地址写入val.txt文件 f.write('%s\n' % fn) elif s == 'trainval2017': with open(save_path, 'w') as f: for fn in patch_fn_list: # 将所有图像名的编号写入trainval.txt文件 f.write('%s\n' % fn) print('Finish Producing %s txt file to %s' % (s, save_path))# 按照train.txt和val.txt将images分类 import shutil import os def my_move(trainlistdir,vallistdir,traindir,valdir): # 打开train.txt文件 fopen = open(trainlistdir, 'r') # 读取图片名称 file_names = fopen.readlines() for file_name in file_names: file_name=file_name.strip('\n') # 图片的路径 traindata = file_name # 把图片复制至traindir路径下 # 如果目标文件夹不存在,则创建它 if not os.path.exists(traindir): os.makedirs(traindir) shutil.move(traindata, traindir) # 同上 fopen = open(vallistdir, 'r') file_names = fopen.readlines() for file_name in file_names: file_name=file_name.strip('\n') valdata = file_name # 如果目标文件夹不存在,则创建它 if not os.path.exists(valdir): os.makedirs(valdir) shutil.move(valdata, valdir) # 存储训练图片名的txt文件地址 trainlistdir=r'/home/ma-user/work/dataset/update_traffic_sign/train2017.txt' # 存储验证图片名的txt文件地址 vallistdir=r'/home/ma-user/work/dataset/update_traffic_sign/val2017.txt' # coco格式数据集的train2017目录 traindir=r'/home/ma-user/work/dataset/update_traffic_sign/images/train2017' # coco格式数据集的val2017目录 valdir=r'/home/ma-user/work/dataset/update_traffic_sign/images/val2017' my_move(trainlistdir,vallistdir,traindir,valdir)# 按照train.txt和val.txt将labels分类 import shutil import os def my_move(datadir, trainlistdir,vallistdir,traindir,valdir): # 打开train.txt文件 fopen = open(trainlistdir, 'r') # 读取图片名称 file_names = fopen.readlines() for file_name in file_names: file_name=file_name.strip('\n') # 图片的路径 tmp_list = file_name.split('/') tmp_list[-2] = 'labels' train_sp = os.path.join('/', *tmp_list) traindata = train_sp.split('.jpg')[-2] + '.txt' # 把图片复制至traindir路径下 # 如果目标文件夹不存在,则创建它 if not os.path.exists(traindir): os.makedirs(traindir) shutil.move(traindata, traindir) # 同上 fopen = open(vallistdir, 'r') file_names = fopen.readlines() for file_name in file_names: file_name=file_name.strip('\n') tmp_list_v = file_name.split('/') tmp_list_v[-2] = 'labels' val_sp = os.path.join('/', *tmp_list_v) valdata = val_sp.split('.jpg')[-2] + '.txt' # 如果目标文件夹不存在,则创建它 if not os.path.exists(valdir): os.makedirs(valdir) shutil.move(valdata, valdir) # labels存储地址 datadir=r'/home/ma-user/work/dataset/update_traffic_sign/labels/' # 存储训练图片名的txt文件地址 trainlistdir=r'/home/ma-user/work/dataset/update_traffic_sign/train2017.txt' # 存储验证图片名的txt文件地址 vallistdir=r'/home/ma-user/work/dataset/update_traffic_sign/val2017.txt' # coco格式数据集的train2017目录 traindir=r'/home/ma-user/work/dataset/update_traffic_sign/labels/train2017' # coco格式数据集的val2017目录 valdir=r'/home/ma-user/work/dataset/update_traffic_sign/labels/val2017' my_move(datadir, trainlistdir,vallistdir,traindir,valdir)# 对images和labels重命名 import os def rename_img_label(images_folder, labels_folder): # 获取文件夹中的文件列表 images = sorted(os.listdir(images_folder)) labels = sorted(os.listdir(labels_folder)) # 重新命名文件 for i, (image_file, label_file) in enumerate(zip(images, labels)): # 生成新的文件名 new_name = f"{i + 1:03d}" # 格式化为三位数 image_ext = os.path.splitext(image_file)[1] # 获取图片扩展名 label_ext = os.path.splitext(label_file)[1] # 获取标签扩展名 # 构建新的完整路径 new_image_path = os.path.join(images_folder, f"{new_name}{image_ext}") new_label_path = os.path.join(labels_folder, f"{new_name}{label_ext}") # 重命名文件 os.rename(os.path.join(images_folder, image_file), new_image_path) os.rename(os.path.join(labels_folder, label_file), new_label_path) print("文件重命名完成。") # 设置train文件夹路径 train_images_folder = '/home/ma-user/work/dataset/update_traffic_sign/images/train2017' train_labels_folder = '/home/ma-user/work/dataset/update_traffic_sign/labels/train2017' # 设置val文件夹路径 val_images_folder = '/home/ma-user/work/dataset/update_traffic_sign/images/val2017' val_labels_folder = '/home/ma-user/work/dataset/update_traffic_sign/labels/val2017' rename_img_label(train_images_folder, train_labels_folder) rename_img_label(val_images_folder, val_labels_folder)import os # 设置文件夹路径 folder_train = '/home/ma-user/work/dataset/update_traffic_sign/images/train2017' folder_val = '/home/ma-user/work/dataset/update_traffic_sign/images/val2017' output_file_train = '/home/ma-user/work/dataset/update_traffic_sign/train2017.txt' # 输出的 TXT 文件名 output_file_val = '/home/ma-user/work/dataset/update_traffic_sign/val2017.txt' # 输出的 TXT 文件名 def writetxt(floder_path, outputfilename): # 获取文件夹中的文件列表 file_names = os.listdir(floder_path) file_names.sort() # 将文件名写入 TXT 文件 with open(outputfilename, 'w') as f: for file_name in file_names: f.write(os.path.join(floder_path, file_name) + '\n') print(f"文件名已写入 {outputfilename}。") writetxt(folder_train, output_file_train) writetxt(folder_val, output_file_val)# 生成json文件(可选) import glob import json import os from PIL import Image def yolo_to_coco_for_subset(yolo_images_folder, yolo_labels_folder, categories): # Initialize COCO dataset structure for the subset coco_format = { "images": [], "annotations": [], "categories": [] } # Add category information for i, category in enumerate(categories): coco_format["categories"].append({ "id": i + 1, "name": category, "supercategory": "none" }) image_id = 0 annotation_id = 0 # image_id = -1 # annotation_id = -1 for image_file in glob.glob(f"{yolo_images_folder}/*.jpg"): print(image_file) # Read image to get width and height with Image.open(image_file) as img: width, height = img.size # Add image information with size coco_format["images"].append({ "id": image_id + 1, "file_name": os.path.basename(image_file), "width": width, "height": height }) # Corresponding annotation file yolo_annotation_file = os.path.join(yolo_labels_folder, os.path.basename(image_file).replace(".jpg", ".txt")) if os.path.exists(yolo_annotation_file): with open(yolo_annotation_file, "r") as file: for line in file: category_id, x_center, y_center, bbox_width, bbox_height = map(float, line.split()) # Convert YOLO format to COCO format x_min = (x_center - bbox_width / 2) * width y_min = (y_center - bbox_height / 2) * height coco_bbox_width = bbox_width * width coco_bbox_height = bbox_height * height # change image_id img_id = int(image_file.split('/')[-1].split('.')[-2]) print(img_id) # Add annotation information coco_format["annotations"].append({ "id": annotation_id + 1, "image_id": img_id, # image_id + 1, "category_id": int(category_id) + 1, "bbox": [x_min, y_min, coco_bbox_width, coco_bbox_height], "area": coco_bbox_width * coco_bbox_height, "segmentation": [], # Optional "iscrowd": 0 }) annotation_id += 1 image_id += 1 return coco_format def save_coco_format(coco_format, output_file): with open(output_file, "w") as file: json.dump(coco_format, file, indent=4) # Example usage yolo_base_folder = "/home/ma-user/work/dataset/update_traffic_sign/" # 父级文件夹 file_path = '/home/ma-user/work/dataset/update_traffic_sign/classes.txt' # 替换为你的txt文件路径 train_json_save_path = '/home/ma-user/work/dataset/update_traffic_sign/annotations/instances_train2017.json' # train json保存路径 val_json_save_path = '/home/ma-user/work/dataset/update_traffic_sign/annotations/instances_val2017.json' # val json保存路径 # 判断文件夹是否存在,若不存在则创建 # 判断文件夹是否存在,若不存在则创建 list_name_train = train_json_save_path.split('/')[:-1] if not os.path.exists(os.path.join(*list_name_train)): os.mkdir(os.path.join('/', *list_name_train)) # 读取txt文件并将每一行转换为列表 categories = [] with open(file_path, 'r') as file: lines = file.readlines() # 读取文件的所有行 for line in lines: categories.append(line.strip()) # 输出结果 print(categories) # Convert train set train_coco_format = yolo_to_coco_for_subset( os.path.join(yolo_base_folder, "images/train2017"), os.path.join(yolo_base_folder, "labels/train2017"), categories ) save_coco_format(train_coco_format, train_json_save_path) # Convert val set val_coco_format = yolo_to_coco_for_subset( os.path.join(yolo_base_folder, "images/val2017"), os.path.join(yolo_base_folder, "labels/val2017"), categories ) save_coco_format(val_coco_format, val_json_save_path)# 查看数据集 import os import random import cv2 import numpy as np from matplotlib import pyplot as plt %matplotlib inline # classes = ["open", "short","mousebite","spur","copper",'pin-hole'] # 类别 classes = ['i1', 'i10', 'i11', 'i12', 'i13', 'i14', 'i15', 'i2', 'i3', 'i4', 'i5', 'i6', 'i7', 'i8', 'i9', 'i50'] file_path = "/home/ma-user/work/dataset/update_traffic_sign/images/train2017" file_list = os.listdir(file_path) img_paths = random.sample(file_list, 4) img_lists = [] for img_path in img_paths: img_path = os.path.join(file_path, img_path) img = cv2.imread(img_path) h, w, _ = img.shape tl = round(0.002 * (h + w) / 2) + 1 color = [random.randint(0, 255) for _ in range(3)] if img_path.endswith('.png'): with open(img_path.replace("images", "labels").replace(".png", ".txt")) as f: labels = f.readlines() if img_path.endswith('.jpg'): with open(img_path.replace("images", "labels").replace(".jpg", ".txt")) as f: labels = f.readlines() for label in labels: l, x, y, wc, hc = [float(x) for x in label.strip().split()] x1 = int((x - wc / 2) * w) y1 = int((y - hc / 2) * h) x2 = int((x + wc / 2) * w) y2 = int((y + hc / 2) * h) cv2.rectangle(img, (x1, y1), (x2, y2), color, thickness=tl, lineType=cv2.LINE_AA) cv2.putText(img,classes[int(l)],(x1,y1-2), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,111,222), 3, cv2.LINE_AA) img_lists.append(cv2.resize(img, (1280, 720))) image = np.concatenate([np.concatenate(img_lists[:2], axis=1), np.concatenate(img_lists[2:], axis=1)], axis=0) plt.rcParams["figure.figsize"] = (20, 10) plt.imshow(image[:,:,::-1]) plt.axis('off') plt.show()【准备mindyolo模型】链接:mindyolo# 步骤1:从OBS迁移数据集 import moxing as mox mox.file.copy_parallel("obs://trafficbuckets/source_code/mindyolo.zip", "/home/ma-user/work/mindyolo.zip") # 形参:源文件->指定位置【修改配置文件】1.yolov8n.yaml以及其继承的coco.yaml,hyp.scratch.low.yaml,yolov8-base.yaml的配置信息coco.yamldata: dataset_name: update_traffic_sign # you can change! train_set: /home/ma-user/work/dataset/update_traffic_sign/train2017.txt # ./coco/train2017.txt # 118287 images # you can change! val_set: /home/ma-user/work/dataset/update_traffic_sign/val2017.txt # ./coco/val2017.txt # 5000 images # you can change! test_set: /home/ma-user/work/dataset/update_traffic_sign/test2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794 # you can change! nc: 16 # class names names: ['i1', 'i10', 'i11', 'i12', 'i13', 'i14', 'i15', 'i2', 'i3', 'i4', 'i5', 'i6', 'i7', 'i8', 'i9', 'i50'] # you can change! train_transforms: [] test_transforms: []yolov8-base.yamlepochs: 500 # total train epochs # you can change! per_batch_size: 2 # 16 * 8 = 128 img_size: 2048 iou_thres: 0.7 conf_free: True sync_bn: True opencv_threads_num: 0 # opencv: disable threading optimizations network: model_name: yolov8 nc: 16 # number of classes # you can change! reg_max: 16 stride: [8, 16, 32] ...【执行训练】python train.py --config ./configs/yolov8/yolov8n.yaml --run_eval True
-
设备型号 M2331-T请问如何实现无预览方式,接收摄像头识别的车牌及图片?另外,是否需要在摄像头上做什么配置?我尝试过的方法:1:IVS_PU_RealPlay开启元数据流后,没有收到任何数据2:IVS_PU_AlarmInfoStatesCallBack_V20布防后,没有收到车牌识别事件及数据
推荐直播
-
GaussDB数据库介绍
2025/01/07 周二 16:00-18:00
Steven 华为云学堂技术讲师
本期直播将介绍GaussDB数据库的发展历程、优势、架构、关键特性和部署模式等,旨在帮助开发者了解GaussDB数据库,并通过手把手实验教大家如何在华为云部署GaussDB数据库和使用gsql连接GaussDB数据库。
去报名 -
DTT年度收官盛典:华为开发者空间大咖汇,共探云端开发创新
2025/01/08 周三 16:30-18:00
Yawei 华为云开发工具和效率首席专家 Edwin 华为开发者空间产品总监
数字化转型进程持续加速,驱动着技术革新发展,华为开发者空间如何巧妙整合鸿蒙、昇腾、鲲鹏等核心资源,打破平台间的壁垒,实现跨平台协同?在科技迅猛发展的今天,开发者们如何迅速把握机遇,实现高效、创新的技术突破?DTT 年度收官盛典,将与大家共同探索华为开发者空间的创新奥秘。
去报名 -
GaussDB应用实战:手把手带你写SQL
2025/01/09 周四 16:00-18:00
Steven 华为云学堂技术讲师
本期直播将围绕数据库中常用的数据类型、数据库对象、系统函数及操作符等内容展开介绍,帮助初学者掌握SQL入门级的基础语法。同时在线手把手教你写好SQL。
去报名
热门标签