Skip to content

Commit a4c2671

Browse files
committed
Add the backgroud images to the train dataset.
1 parent db437fd commit a4c2671

File tree

7 files changed

+167
-148
lines changed

7 files changed

+167
-148
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
#### YOLOV5格式数据→COCO
2-
- 值得一提的是,由标注软件[labelImg](https://github.com/tzutalin/labelImg)标注所得yolo格式数据,也可由该脚本做转换。前提是满足以下数据目录结构。
1+
## YOLO2COCO
2+
3+
#### YOLOV5格式数据 → COCO
4+
- 可以将一些相似的背景图像加入到训练中,直接将背景图像放入`backgroud_images`目录即可,转换程序会自动扫描该目录,添加到训练集中。
35
- YOLOV5训练格式目录结构(详情参见`dataset/YOLOV5`):
46
```text
57
YOLOV5
68
├── classes.txt
9+
├── background_images # 背景图像,一般是和要检测的对象容易混淆的图像
10+
│ └── bg1.jpeg
711
├── images
812
│ ├── images(13).jpg
913
│ └── images(3).jpg
@@ -15,8 +19,10 @@
1519
```
1620
1721
- 转换
22+
- `--dir_path`:整理好的数据集所在目录
23+
- `--mode_list`:指定生成的json类型,前提是要有对应的txt文件,可单独指定。
1824
```shell
19-
python yolov5_2_coco.py --dir_path dataset/YOLOV5
25+
python yolov5_2_coco.py --dir_path dataset/YOLOV5 --mode_list train,val
2026
```
2127
- 转换后目录结构(详情参见`dataset/YOLOV5_COCO_format`):
2228
```text
@@ -25,12 +31,13 @@
2531
│ ├── instances_train2017.json
2632
│ └── instances_val2017.json
2733
├── train2017
28-
│ └── 000000000001.jpg
34+
│ ├── 000000000001.jpg
35+
│ └── 000000000002.jpg # 这个是背景图像
2936
└── val2017
3037
└── 000000000001.jpg
3138
```
3239
33-
#### YOLOV5 yaml数据描述文件转COCO
40+
#### YOLOV5 yaml数据描述文件转COCO
3441
3542
- YOLOV5 yaml 数据文件需要包含:
3643
```text
@@ -57,7 +64,7 @@
5764
python yolov5_yaml_2_coco.py --yaml_path dataset/YOLOV5_yaml/sample.yaml
5865
```
5966

60-
#### darknet格式数据COCO
67+
#### darknet格式数据COCO
6168
- darknet训练数据目录结构(详情参见`dataset/darknet`):
6269
```text
6370
darknet

coco_visual.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ def visualization_bbox(num_image, json_path, img_path):
1515
annotation_json = json.load(annos)
1616

1717
# 统计json文件的关键字长度
18-
print('the annotation_json num_key is:', len(annotation_json))
18+
print('The annotation_json num_key is:', len(annotation_json))
1919

2020
# 读出json文件的关键字
21-
print('the annotation_json key is:', annotation_json.keys())
21+
print('The annotation_json key is:', annotation_json.keys())
2222

2323
# json文件中包含的图片数量
24-
print('the annotation_json num_images is:', len(annotation_json['images']))
24+
print('The annotation_json num_images is:', len(annotation_json['images']))
2525

2626
# 获取所有类别数
2727
categories = annotation_json['categories']
23.2 KB
Loading
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info": {"year": 2021, "version": "1.0", "description": "For object detection", "date_created": "2021"}, "images": [{"date_captured": "2021", "file_name": "000000000001.jpg", "id": 1, "height": 224, "width": 224}], "licenses": [{"id": 1, "name": "Apache License v2.0", "url": "https://github.com/RapidAI/YOLO2COCO/LICENSE"}], "type": "instances", "annotations": [{"segmentation": [[18.000080000000004, 2.999920000000003, 105.000112, 2.999920000000003, 105.000112, 89.000016, 18.000080000000004, 89.000016]], "area": 7482.011104003072, "iscrowd": 0, "image_id": 1, "bbox": [18.000080000000004, 2.999920000000003, 87.000032, 86.000096], "category_id": 1, "id": 1}, {"segmentation": [[126.99993599999999, 3.9999679999999955, 210.999936, 3.9999679999999955, 210.999936, 88.999904, 126.99993599999999, 88.999904]], "area": 7139.994624000001, "iscrowd": 0, "image_id": 1, "bbox": [126.99993599999999, 3.9999679999999955, 84.0, 84.999936], "category_id": 1, "id": 2}, {"segmentation": [[74.99990400000002, 76.000064, 150.99996800000002, 76.000064, 150.99996800000002, 153.000064, 74.99990400000002, 153.000064]], "area": 5852.004927999999, "iscrowd": 0, "image_id": 1, "bbox": [74.99990400000002, 76.000064, 76.000064, 77.0], "category_id": 1, "id": 3}, {"segmentation": [[12.000127999999997, 135.000096, 97.00006400000001, 135.000096, 97.00006400000001, 220.00003200000003, 12.000127999999997, 220.00003200000003]], "area": 7224.989120004097, "iscrowd": 0, "image_id": 1, "bbox": [12.000127999999997, 135.000096, 84.999936, 84.999936], "category_id": 1, "id": 4}, {"segmentation": [[132.00006399999998, 136.999968, 215.00012799999996, 136.999968, 215.00012799999996, 220.00003199999998, 132.00006399999998, 220.00003199999998]], "area": 6889.010624004095, "iscrowd": 0, "image_id": 1, "bbox": [132.00006399999998, 136.999968, 83.000064, 83.000064], "category_id": 1, "id": 5}], "categories": [{"supercategory": "stamp", "id": 1, "name": "stamp"}]}
1+
{"info": {"year": 2022, "version": "1.0", "description": "For object detection", "date_created": "2022"}, "images": [{"date_captured": "2022", "file_name": "000000000001.jpg", "id": 1, "height": 224, "width": 224}, {"date_captured": "2022", "file_name": "000000000002.jpg", "id": 2, "height": 424, "width": 550}], "licenses": [{"id": 1, "name": "Apache License v2.0", "url": "https://github.com/RapidAI/YOLO2COCO/LICENSE"}], "type": "instances", "annotations": [{"segmentation": [[18.000080000000004, 2.999920000000003, 105.000112, 2.999920000000003, 105.000112, 89.000016, 18.000080000000004, 89.000016]], "area": 7482.011104003072, "iscrowd": 0, "image_id": 1, "bbox": [18.000080000000004, 2.999920000000003, 87.000032, 86.000096], "category_id": 1, "id": 1}, {"segmentation": [[126.99993599999999, 3.9999679999999955, 210.999936, 3.9999679999999955, 210.999936, 88.999904, 126.99993599999999, 88.999904]], "area": 7139.994624000001, "iscrowd": 0, "image_id": 1, "bbox": [126.99993599999999, 3.9999679999999955, 84.0, 84.999936], "category_id": 1, "id": 2}, {"segmentation": [[74.99990400000002, 76.000064, 150.99996800000002, 76.000064, 150.99996800000002, 153.000064, 74.99990400000002, 153.000064]], "area": 5852.004927999999, "iscrowd": 0, "image_id": 1, "bbox": [74.99990400000002, 76.000064, 76.000064, 77.0], "category_id": 1, "id": 3}, {"segmentation": [[12.000127999999997, 135.000096, 97.00006400000001, 135.000096, 97.00006400000001, 220.00003200000003, 12.000127999999997, 220.00003200000003]], "area": 7224.989120004097, "iscrowd": 0, "image_id": 1, "bbox": [12.000127999999997, 135.000096, 84.999936, 84.999936], "category_id": 1, "id": 4}, {"segmentation": [[132.00006399999998, 136.999968, 215.00012799999996, 136.999968, 215.00012799999996, 220.00003199999998, 132.00006399999998, 220.00003199999998]], "area": 6889.010624004095, "iscrowd": 0, "image_id": 1, "bbox": [132.00006399999998, 136.999968, 83.000064, 83.000064], "category_id": 1, "id": 5}, {"segmentation": [], "area": 0, "iscrowd": 0, "image_id": 2, "bbox": [], "category_id": -1, "id": 6}], "categories": [{"supercategory": "stamp", "id": 1, "name": "stamp"}]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info": {"year": 2021, "version": "1.0", "description": "For object detection", "date_created": "2021"}, "images": [{"date_captured": "2021", "file_name": "000000000001.jpg", "id": 1, "height": 248, "width": 203}], "licenses": [{"id": 1, "name": "Apache License v2.0", "url": "https://github.com/RapidAI/YOLO2COCO/LICENSE"}], "type": "instances", "annotations": [{"segmentation": [[18.999988000000002, 16.999904, 183.000034, 16.999904, 183.000034, 178.999952, 18.999988000000002, 178.999952]], "area": 26568.015324002205, "iscrowd": 0, "image_id": 1, "bbox": [18.999988000000002, 16.999904, 164.000046, 162.000048], "category_id": 1, "id": 6}], "categories": [{"supercategory": "stamp", "id": 1, "name": "stamp"}]}
1+
{"info": {"year": 2022, "version": "1.0", "description": "For object detection", "date_created": "2022"}, "images": [{"date_captured": "2022", "file_name": "000000000001.jpg", "id": 1, "height": 248, "width": 203}], "licenses": [{"id": 1, "name": "Apache License v2.0", "url": "https://github.com/RapidAI/YOLO2COCO/LICENSE"}], "type": "instances", "annotations": [{"segmentation": [[18.999988000000002, 16.999904, 183.000034, 16.999904, 183.000034, 178.999952, 18.999988000000002, 178.999952]], "area": 26568.015324002205, "iscrowd": 0, "image_id": 1, "bbox": [18.999988000000002, 16.999904, 164.000046, 162.000048], "category_id": 1, "id": 7}], "categories": [{"supercategory": "stamp", "id": 1, "name": "stamp"}]}
47.1 KB
Loading

0 commit comments

Comments
 (0)