Skip to content

Commit 0823c19

Browse files
authored
Accept issue #5
1 parent 10c02e8 commit 0823c19

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@
9393
├── train.txt
9494
└── val.txt
9595
```
96-
96+
- **train.txt**和**val.txt**中图像路径,以下两种均可:
97+
- 相对于**根目录**的路径
98+
```text
99+
dataset/YOLOV5/images/images(3).jpg
100+
```
101+
- 相对于**dataset/YOLOV5**的相对路径
102+
```text
103+
images/images(3).jpg
104+
```
97105
- 转换
98106
```shell
99107
python yolov5_2_coco.py --dir_path dataset/YOLOV5 --mode_list train,val
@@ -102,17 +110,17 @@
102110
- `--mode_list`:指定生成的json,前提是要有对应的txt文件,可单独指定。(e.g. `train,val,test`)
103111
104112
- 转换后目录结构(详情参见`dataset/YOLOV5_COCO_format`):
105-
```text
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
115-
```
113+
```text
114+
YOLOV5_COCO_format
115+
├── annotations
116+
│ ├── instances_train2017.json
117+
│ └── instances_val2017.json
118+
├── train2017
119+
│ ├── 000000000001.jpg
120+
│ └── 000000000002.jpg # 这个是背景图像
121+
└── val2017
122+
└── 000000000001.jpg
123+
```
116124
</details>
117125
118126
#### YOLOV5 YAML描述文件 → COCO

docs/README_en.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,21 @@ English | [简体中文](../README.md)
9393
├── train.txt
9494
└── val.txt
9595
```
96-
96+
- The image paths in train.txt and val.txt can be either:
97+
- Path relative to **root directory**:
98+
```text
99+
dataset/YOLOV5/images/images(3).jpg
100+
```
101+
- Path relative to **dataset/YOLOV5**:
102+
```text
103+
images/images(3).jpg
104+
```
97105
- Convert
98106
```shell
99107
python yolov5_2_coco.py --dir_path dataset/YOLOV5 --mode_list train,val
100108
```
101109
- `--dir_path`: the directory where the collated dataset is located
102-
- `--mode_list`: specify the generated json, provided that there is a corresponding txt file, which can be specified separately. (e.g. `-train,val,test`)
110+
- `--mode_list`: specify the generated json, provided that there is a corresponding txt file, which can be specified separately. (e.g. `train,val,test`)
103111

104112
- The structure of the converted directory (see `dataset/YOLOV5_COCO_format` for details)
105113
```text

yolov5_2_coco.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ def convert(self, img_list, save_img_dir, mode):
117117

118118
def get_image_info(self, img_path, img_id, save_img_dir):
119119
img_path = Path(img_path)
120+
if not img_path.as_posix().__contains__(self.raw_data_dir.as_posix()):
121+
# relative path (relative to the raw_data_dir)
122+
# e.g. images/images(3).jpg
123+
img_path = self.raw_data_dir / img_path
124+
120125
self.verify_exists(img_path)
121126

122127
new_img_name = f'{img_id:012d}.jpg'

0 commit comments

Comments
 (0)