Skip to content

Commit de6a4f3

Browse files
committed
Optim code and update README
1 parent 43dc25d commit de6a4f3

File tree

6 files changed

+231
-155
lines changed

6 files changed

+231
-155
lines changed

README.md

Lines changed: 143 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -9,142 +9,162 @@
99
<a href="./LICENSE"><img src="https://img.shields.io/badge/License-Apache%202-dfd.svg"></a>
1010
</p>
1111

12-
#### LabelImg标注数据 → YOLOV5格式
13-
-[labelImg](https://github.com/tzutalin/labelImg)库标注的yolo数据格式一键转换为YOLOV5格式数据
14-
- labelImg标注数据目录结构如下(详情参见`dataset/labelImg_dataset`):
15-
```text
16-
labelImg_dataset
17-
├── classes.txt
18-
├── images(13).jpg
19-
├── images(13).txt
20-
├── images(3).jpg
21-
├── images(3).txt
22-
├── images4.jpg
23-
├── images4.txt
24-
├── images5.jpg
25-
├── images5.txt
26-
├── images6.jpg
27-
├── images7.jpg
28-
└── images7.txt
29-
```
30-
- 转换
31-
```shell
32-
python labelImg_2_yolov5.py --src_dir dataset/labelImg_dataset --out_dir dataset/labelImg_dataset_output
33-
```
34-
- `--src_dir`:labelImg标注后所在目录
35-
- `--out_dir`: 转换之后的数据存放位置
36-
- 转换后目录结构(详情参见`dataset/labelImg_dataset_output`):
37-
```text
38-
labelImg_dataset_output/
39-
├── classes.txt
40-
├── images
41-
│   ├── images(13).jpg
42-
│   ├── images(3).jpg
43-
│   ├── images4.jpg
44-
│   ├── images5.jpg
45-
│   └── images7.jpg
46-
├── labels
47-
│   ├── images(13).txt
48-
│   ├── images(3).txt
49-
│   ├── images4.txt
50-
│   ├── images5.txt
51-
│   └── images7.txt
52-
├── non_labels # 这是没有标注txt的图像
53-
│   └── images6.jpg
54-
├── test.txt
55-
├── train.txt
56-
└── val.txt
57-
```
58-
- 可以进一步直接对`dataset/labelImg_dataset_output`目录作转COCO的转换
59-
```shell
60-
python yolov5_2_coco.py --dir_path dataset/lablelImg_dataset_output
61-
```
6212

13+
#### labelImg标注yolo格式数据 → YOLOV5格式
14+
<details>
6315

64-
#### YOLOV5格式数据 → COCO
65-
- 可以将一些背景图像加入到训练中,具体做法是:直接将背景图像放入`backgroud_images`目录即可。
66-
- 转换程序会自动扫描该目录,添加到训练集中,可以无缝集成后续[YOLOX](https://github.com/Megvii-BaseDetection/YOLOX)的训练。
67-
- YOLOV5训练格式目录结构(详情参见`dataset/YOLOV5`):
16+
-[labelImg](https://github.com/tzutalin/labelImg)库标注的yolo数据格式一键转换为YOLOV5格式数据
17+
- labelImg标注数据目录结构如下(详情参见`dataset/labelImg_dataset`):
6818
```text
69-
YOLOV5
70-
├── classes.txt
71-
├── background_images # 一般是和要检测的对象容易混淆的图像
72-
│ └── bg1.jpeg
73-
├── images
74-
│ ├── images(13).jpg
75-
│ └── images(3).jpg
76-
├── labels
77-
│ ├── images(13).txt
78-
│ └── images(3).txt
79-
├── train.txt
80-
└── val.txt
19+
labelImg_dataset
20+
├── classes.txt
21+
├── images(13).jpg
22+
├── images(13).txt
23+
├── images(3).jpg
24+
├── images(3).txt
25+
├── images4.jpg
26+
├── images4.txt
27+
├── images5.jpg
28+
├── images5.txt
29+
├── images6.jpg # 注意这个是没有标注的
30+
├── images7.jpg
31+
└── images7.txt
8132
```
82-
83-
- 转换
33+
- 转换
8434
```shell
85-
python yolov5_2_coco.py --dir_path dataset/YOLOV5 --mode_list train,val
86-
```
87-
- `--dir_path`:整理好的数据集所在目录
88-
- `--mode_list`:指定生成的json,前提是要有对应的txt文件,可单独指定。(e.g. `train,val,test`
89-
90-
- 转换后目录结构(详情参见`dataset/YOLOV5_COCO_format`):
91-
```text
92-
YOLOV5_COCO_format
93-
├── annotations
94-
│ ├── instances_train2017.json
95-
│ └── instances_val2017.json
96-
├── train2017
97-
│ ├── 000000000001.jpg
98-
│ └── 000000000002.jpg # 这个是背景图像
99-
└── val2017
100-
└── 000000000001.jpg
35+
python labelImg_2_yolov5.py --src_dir dataset/labelImg_dataset \
36+
--out_dir dataset/labelImg_dataset_output \
37+
--val_ratio 0.2 \
38+
--have_test true \
39+
--test_ratio 0.2
10140
```
41+
- `--src_dir`:labelImg标注后所在目录
42+
- `--out_dir`: 转换之后的数据存放位置
43+
- `--val_ratio`:生成验证集占整个数据的比例,默认是`0.2`
44+
- `--have_test`:是否生成test部分数据,默认是`True`
45+
- `--test_ratio`:test数据整个数据百分比,默认是`0.2`
10246
103-
#### YOLOV5 YAML描述文件 → COCO
104-
- YOLOV5 yaml 数据文件需要包含:
47+
- 转换后目录结构(详情参见`dataset/labelImg_dataset_output`):
10548
```text
106-
YOLOV5_yaml
107-
├── images
108-
│   ├── train
109-
│   │   ├── images(13).jpg
110-
│   │   └── images(3).jpg
111-
│   └── val
112-
│   ├── images(13).jpg
113-
│   └── images(3).jpg
114-
├── labels
115-
│   ├── train
116-
│   │   ├── images(13).txt
117-
│   │   └── images(3).txt
118-
│   └── val
119-
│   ├── images(13).txt
120-
│   └── images(3).txt
121-
└── sample.yaml
49+
labelImg_dataset_output/
50+
├── classes.txt
51+
├── images
52+
│   ├── images(13).jpg
53+
│   ├── images(3).jpg
54+
│   ├── images4.jpg
55+
│   ├── images5.jpg
56+
│   └── images7.jpg
57+
├── labels
58+
│   ├── images(13).txt
59+
│   ├── images(3).txt
60+
│   ├── images4.txt
61+
│   ├── images5.txt
62+
│   └── images7.txt
63+
├── non_labels # 这是没有标注图像的目录
64+
│   └── images6.jpg
65+
├── test.txt
66+
├── train.txt
67+
└── val.txt
68+
```
69+
- 可以进一步直接对`dataset/labelImg_dataset_output`目录作转COCO的转换
70+
```shell
71+
python yolov5_2_coco.py --dir_path dataset/lablelImg_dataset_output
12272
```
12373
124-
- 转换
125-
```shell
126-
python yolov5_yaml_2_coco.py --yaml_path dataset/YOLOV5_yaml/sample.yaml
127-
```
74+
</details>
75+
76+
#### YOLOV5格式数据 → COCO
77+
<details>
78+
79+
- 可以将一些背景图像加入到训练中,具体做法是:直接将背景图像放入`backgroud_images`目录即可。
80+
- 转换程序会自动扫描该目录,添加到训练集中,可以无缝集成后续[YOLOX](https://github.com/Megvii-BaseDetection/YOLOX)的训练。
81+
- YOLOV5训练格式目录结构(详情参见`dataset/YOLOV5`):
82+
```text
83+
YOLOV5
84+
├── classes.txt
85+
├── background_images # 一般是和要检测的对象容易混淆的图像
86+
│ └── bg1.jpeg
87+
├── images
88+
│ ├── images(13).jpg
89+
│ └── images(3).jpg
90+
├── labels
91+
│ ├── images(13).txt
92+
│ └── images(3).txt
93+
├── train.txt
94+
└── val.txt
95+
```
12896
129-
#### darknet格式数据 → COCO
130-
- darknet训练数据目录结构(详情参见`dataset/darknet`):
97+
- 转换
98+
```shell
99+
python yolov5_2_coco.py --dir_path dataset/YOLOV5 --mode_list train,val
100+
```
101+
- `--dir_path`:整理好的数据集所在目录
102+
- `--mode_list`:指定生成的json,前提是要有对应的txt文件,可单独指定。(e.g. `train,val,test`)
103+
104+
- 转换后目录结构(详情参见`dataset/YOLOV5_COCO_format`):
131105
```text
132-
darknet
133-
├── class.names
134-
├── gen_config.data
135-
├── gen_train.txt
136-
├── gen_valid.txt
137-
└── images
138-
├── train
139-
└── valid
106+
YOLOV5_COCO_format
107+
├── annotations
108+
│ ├── instances_train2017.json
109+
│ └── instances_val2017.json
110+
├── train2017
111+
│ ├── 000000000001.jpg
112+
│ └── 000000000002.jpg # 这个是背景图像
113+
└── val2017
114+
└── 000000000001.jpg
140115
```
116+
</details>
141117

142-
- 转换
143-
```shell
144-
python darknet2coco.py --data_path dataset/darknet/gen_config.data
145-
```
118+
#### YOLOV5 YAML描述文件 → COCO
119+
<details>
120+
121+
- YOLOV5 yaml 数据文件目录结构如下(详情参见`dataset/YOLOV5_yaml`):
122+
```text
123+
YOLOV5_yaml
124+
├── images
125+
│   ├── train
126+
│   │   ├── images(13).jpg
127+
│   │   └── images(3).jpg
128+
│   └── val
129+
│   ├── images(13).jpg
130+
│   └── images(3).jpg
131+
├── labels
132+
│   ├── train
133+
│   │   ├── images(13).txt
134+
│   │   └── images(3).txt
135+
│   └── val
136+
│   ├── images(13).txt
137+
│   └── images(3).txt
138+
└── sample.yaml
139+
```
140+
141+
- 转换
142+
```shell
143+
python yolov5_yaml_2_coco.py --yaml_path dataset/YOLOV5_yaml/sample.yaml
144+
```
145+
146+
#### darknet格式数据 → COCO
147+
- darknet训练数据目录结构(详情参见`dataset/darknet`):
148+
```text
149+
darknet
150+
├── class.names
151+
├── gen_config.data
152+
├── gen_train.txt
153+
├── gen_valid.txt
154+
└── images
155+
├── train
156+
└── valid
157+
```
158+
159+
- 转换
160+
```shell
161+
python darknet2coco.py --data_path dataset/darknet/gen_config.data
162+
```
163+
</details>
146164

147165
#### 可视化COCO格式下图像
166+
<details>
167+
148168
```shell
149169
python coco_visual.py --vis_num 1 \
150170
--json_path dataset/YOLOV5_COCO_format/annotations/instances_train2017.json \
@@ -155,5 +175,8 @@ python coco_visual.py --vis_num 1 \
155175
- `--json_path`:查看图像的json文件路径
156176
- `--img_dir`: 查看图像所在的目录
157177

178+
</details>
179+
180+
158181
#### 相关资料
159182
- [MSCOCO数据标注详解](https://blog.csdn.net/wc781708249/article/details/79603522)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dataset\labelImg_dataset_output\images\images(3).jpg
1+
dataset\labelImg_dataset_output\images\images5.jpg

dataset/labelImg_dataset_output/train.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dataset\labelImg_dataset_output\images\images(13).jpg
12
dataset\labelImg_dataset_output\images\images4.jpg
3+
dataset\labelImg_dataset_output\images\images(3).jpg
24
dataset\labelImg_dataset_output\images\images5.jpg
3-
dataset\labelImg_dataset_output\images\images7.jpg
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dataset\labelImg_dataset_output\images\images(13).jpg
1+
dataset\labelImg_dataset_output\images\images7.jpg

docs/README_en.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ English | [简体中文](../README.md)
99
<a href=". /LICENSE"><img src="https://img.shields.io/badge/License-Apache%202-dfd.svg"></a>
1010
</p>
1111

12-
#### LabelImg label data → YOLOV5 format
12+
#### labelImg label data → YOLOV5 format
13+
<details>
14+
<summary>Click to expand</summary>
15+
1316
- Convert the yolo data format marked by the [labelImg](https://github.com/tzutalin/labelImg) library to YOLOV5 format data with one click
1417
- The labelImg label data directory structure is as follows (see `dataset/labelImg_dataset` for details):
1518
````text
@@ -28,11 +31,19 @@ English | [简体中文](../README.md)
2831
└── images7.txt
2932
````
3033
- Convert
31-
```shell
32-
python labelImg_2_yolov5.py --src_dir dataset/labelImg_dataset --out_dir dataset/labelImg_dataset_output
33-
````
34-
- `--src_dir`: the directory where labelImg is marked
35-
- `--out_dir`: The data storage location after conversion
34+
```shell
35+
python labelImg_2_yolov5.py --src_dir dataset/labelImg_dataset \
36+
--out_dir dataset/labelImg_dataset_output \
37+
--val_ratio 0.2 \
38+
--have_test true \
39+
--test_ratio 0.2
40+
```
41+
- `--src_dir`: the directory where labelImg is stored after labeling.
42+
- `--out_dir`: the location where the data is stored after conversion.
43+
- `--val_ratio`: the ratio of the generated validation set to the whole data, default is `0.2`.
44+
- `--have_test`: whether to generate the test part of the data, the default is `True`.
45+
- `--test_ratio`: percentage of the whole data of the test data, default is `0.2`.
46+
3647
- Converted directory structure (see `dataset/labelImg_dataset_output` for details):
3748
````text
3849
labelImg_dataset_output/
@@ -49,7 +60,7 @@ English | [简体中文](../README.md)
4960
│   ├── images4.txt
5061
│   ├── images5.txt
5162
│   └── images7.txt
52-
├── non_labels # This is the image without label txt
63+
├── non_labels # This is the catalog without the labeled images.
5364
│   └── images6.jpg
5465
├── test.txt
5566
├── train.txt
@@ -59,8 +70,12 @@ English | [简体中文](../README.md)
5970
```shell
6071
python yolov5_2_coco.py --dir_path dataset/labellImg_dataset_output
6172
````
73+
</details>
6274
6375
#### YOLOV5 format data → COCO
76+
<details>
77+
<summary>Click to expand</summary>
78+
6479
- Some background images can be added to the training by directly placing them into the `backgroud_images` directory.
6580
- The conversion program will automatically scan this directory and add it to the training set, allowing seamless integration with subsequent [YOLOX](https://github.com/Megvii-BaseDetection/YOLOX) training.
6681
- YOLOV5 training format directory structure (see `dataset/YOLOV5` for details).
@@ -98,8 +113,12 @@ English | [简体中文](../README.md)
98113
└── val2017
99114
└── 000000000001.jpg
100115
```
116+
</details>
101117

102118
#### YOLOV5 YAML description file → COCO
119+
<details>
120+
<summary>Click to expand</summary>
121+
103122
- The YOLOV5 yaml data file needs to contain.
104123
```text
105124
YOLOV5_yaml
@@ -142,8 +161,12 @@ English | [简体中文](../README.md)
142161
```shell
143162
python darknet2coco.py --data_path dataset/darknet/gen_config.data
144163
```
164+
</details>
145165

146166
#### Visualize images in COCO format
167+
<details>
168+
<summary>Click to expand</summary>
169+
147170
```shell
148171
python coco_visual.py --vis_num 1 \
149172
--json_path dataset/YOLOV5_COCO_format/annotations/instances_train2017.json \
@@ -154,5 +177,8 @@ python coco_visual.py --vis_num 1 \
154177
- `--json_path`: path to the json file of the image to view
155178
- `--img_dir`: view the directory where the image is located
156179

180+
</details>
181+
182+
157183
#### Related information
158184
- [MSCOCO Data Annotation Details](https://blog.csdn.net/wc781708249/article/details/79603522)

0 commit comments

Comments
 (0)