From 3abb3e8480a7c41ce077318af01ffbe017bc3726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=A5=87?= <50481269+jztddlq@users.noreply.github.com> Date: Fri, 11 Dec 2020 15:33:53 +0800 Subject: [PATCH 1/6] Update dataset.py create own get_image_id function --- dataset.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dataset.py b/dataset.py index 968a5514..8f62fe27 100644 --- a/dataset.py +++ b/dataset.py @@ -424,9 +424,9 @@ def get_image_id(filename:str) -> int: >>> return int(lv+no) """ raise NotImplementedError("Create your own 'get_image_id' function") - lv, no = os.path.splitext(os.path.basename(filename))[0].split("_") - lv = lv.replace("level", "") - no = f"{int(no):04d}" + no = os.path.splitext(os.path.basename(filename))[0] + no = f"{int(no):05d}" + lv =str(1) return int(lv+no) From ad8c7e2c8a405cd2424785eff2ad87d8581973ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=A5=87?= <50481269+jztddlq@users.noreply.github.com> Date: Fri, 11 Dec 2020 15:36:25 +0800 Subject: [PATCH 2/6] Update coco_eval.py coco-eval shape --- tool/tv_reference/coco_eval.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tool/tv_reference/coco_eval.py b/tool/tv_reference/coco_eval.py index 730a16af..c3f515e3 100644 --- a/tool/tv_reference/coco_eval.py +++ b/tool/tv_reference/coco_eval.py @@ -273,6 +273,7 @@ def loadRes(self, resFile): elif 'bbox' in anns[0] and not anns[0]['bbox'] == []: res.dataset['categories'] = copy.deepcopy(self.dataset['categories']) for id, ann in enumerate(anns): + ann['bbox'] = ann['bbox'][0] bb = ann['bbox'] x1, x2, y1, y2 = [bb[0], bb[0] + bb[2], bb[1], bb[1] + bb[3]] if 'segmentation' not in ann: From d859bee8cb022b530a2edcfa41ce92a7169918ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=A5=87?= <50481269+jztddlq@users.noreply.github.com> Date: Fri, 11 Dec 2020 15:43:46 +0800 Subject: [PATCH 3/6] Add files via upload xml to YOLOv4 train.txt --- xml2yolov4.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 xml2yolov4.py diff --git a/xml2yolov4.py b/xml2yolov4.py new file mode 100644 index 00000000..1b9a2c60 --- /dev/null +++ b/xml2yolov4.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Aug 26 15:05:40 2020 + +@author: Liu qi +""" + + +from xml.dom.minidom import parse +import xml.dom.minidom +import os +import shutil + +def get_file_path(file_path): + ''' + :param filename:修改后路径 + :param file_path: 图片所在label文件夹目录 + :param h,w: 图片的长宽 + :return:图片的路径列表 + ''' + img_paths = [] + img_names = os.listdir(file_path) + for img_name in img_names: + img_path = os.path.join(file_path, img_name) + img_paths.append(img_path) + return img_paths +def mkdir_if_not_exist(path): + if not os.path.exists(os.path.join(*path)): + os.makedirs(os.path.join(*path)) + return os.path.join(*path) +path = r'D:\bonc\DPcase\yolov4_yolov5\nonmotor\new_data_1_label' +mkdir_if_not_exist(['./images/train/']) +xml_paths = get_file_path(path) + +label_dict = {"bicycle":0, + "express_bicycle":1, + "express_tricycle":2, + "tricycle":3, + "electric_bicycle":4,} +f = open('train_1.txt','w+') + +for xml_path in xml_paths: + domTree = parse(xml_path) + rootNode = domTree.documentElement + #img_name + filename = rootNode.getElementsByTagName("filename") + img_name = filename[0].childNodes[0].data + #move image + #shutil.copy('D:/bonc/DPcase/non-motor vehicle/new_data_1/'+img_name,'../data/'+img_name) + + rm = True + xmlobjects = rootNode.getElementsByTagName("object") + for xmlobject in xmlobjects: + obname = xmlobject.getElementsByTagName("name") + label_name = obname[0].childNodes[0].data + if label_name in label_dict: + if rm: + f.write('\n') + f.write('../nonmotor/images/train/'+img_name) + rm =False + label = label_dict[label_name] + + obbox = xmlobject.getElementsByTagName("bndbox") + + obxmin = obbox[0].getElementsByTagName("xmin") + xmin = obxmin[0].childNodes[0].data + + obymin = obbox[0].getElementsByTagName("ymin") + ymin = obymin[0].childNodes[0].data + + obxmax = obbox[0].getElementsByTagName("xmax") + xmax = obxmax[0].childNodes[0].data + + obymax = obbox[0].getElementsByTagName("ymax") + ymax = obymax[0].childNodes[0].data + + + bbox_info=" %d,%d,%d,%d,%d" % (int(xmin), int(ymin), int(xmax), int(ymax), label) + f.write(bbox_info) +f.close() \ No newline at end of file From b749286ca1a831b8a77e166ccc6563554f407d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=A5=87?= <50481269+jztddlq@users.noreply.github.com> Date: Fri, 11 Dec 2020 15:48:34 +0800 Subject: [PATCH 4/6] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c2e32f8b..f3e0d095 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ ![](https://img.shields.io/static/v1?label=pytorch&message=1.4&color=) [![](https://img.shields.io/static/v1?label=license&message=Apache2&color=green)](./License.txt) +Add own xml to yolov4 train.txt +match the coco evaluate shape requirement + A minimal PyTorch implementation of YOLOv4. - Paper Yolo v4: https://arxiv.org/abs/2004.10934 - Source code:https://github.com/AlexeyAB/darknet From b3be795ba9f492c4c59a04cb94bab1842d70b75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=A5=87?= <50481269+jztddlq@users.noreply.github.com> Date: Fri, 11 Dec 2020 15:49:04 +0800 Subject: [PATCH 5/6] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f3e0d095..39d2481d 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ ![](https://img.shields.io/static/v1?label=pytorch&message=1.4&color=) [![](https://img.shields.io/static/v1?label=license&message=Apache2&color=green)](./License.txt) -Add own xml to yolov4 train.txt -match the coco evaluate shape requirement +-Add own xml to yolov4 train.txt +-match the coco evaluate shape requirement A minimal PyTorch implementation of YOLOv4. - Paper Yolo v4: https://arxiv.org/abs/2004.10934 From 89df4d6ceb10b2e6f8f2a307d61f5ecf648d3eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=A5=87?= <50481269+jztddlq@users.noreply.github.com> Date: Fri, 11 Dec 2020 15:49:38 +0800 Subject: [PATCH 6/6] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39d2481d..0a46d1d2 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,9 @@ ![](https://img.shields.io/static/v1?label=pytorch&message=1.4&color=) [![](https://img.shields.io/static/v1?label=license&message=Apache2&color=green)](./License.txt) --Add own xml to yolov4 train.txt --match the coco evaluate shape requirement +-Add own xml to yolov4 train.txt. + +-match the coco evaluate shape requirement. A minimal PyTorch implementation of YOLOv4. - Paper Yolo v4: https://arxiv.org/abs/2004.10934