Skip to content

Commit 4446715

Browse files
committed
fix bugs;add README
1 parent e7f8760 commit 4446715

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@
4848
└── 000000000001.jpg
4949
```
5050
51+
#### YOLOV5 yaml数据描述文件转→COCO
52+
53+
- YOLOV5 yaml 数据文件需要包含:
54+
```text
55+
YOLOV5 yaml
56+
├── path(str, the root path)
57+
├── train(Train sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..])
58+
├── val(val sets, similar as train)
59+
60+
```
61+
62+
- 转换
63+
```shell
64+
python yolov5_cfgfile_2_coco.py --cfg_file dataset/sample.yaml
65+
```
66+
5167
#### 可视化COCO格式标注格式
5268
```shell
5369
python coco_visual.py --vis_num 1 \

dataset/sample.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
2+
path: /the/root/path/to/data # dataset root dir
3+
train: [data1/images/train/, data2/images/train/]
4+
val: [data1/images/val/, data2/images/val/]
5+
6+
# Classes
7+
nc: 3 # number of classes
8+
names: ['class1', 'class2', 'class3'] # class names

yolov5_cfgfile_2_coco.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __init__(self, cfg_file):
6565
# 构建json内容结构
6666
self.type = 'instances'
6767
self.categories = []
68+
self._get_category()
6869
self.annotation_id = 1
6970

7071
self.info = {
@@ -87,11 +88,11 @@ def _get_category(self):
8788
'id': i,
8889
'name': category,
8990
})
90-
self.categories.append({
91-
'supercategory': 'Background',
92-
'id': 0,
93-
'name': 'Background',
94-
})
91+
# self.categories.append({
92+
# 'supercategory': 'Background',
93+
# 'id': 0,
94+
# 'name': 'Background',
95+
# })
9596

9697
def generate(self):
9798
self.train_files = self.getfiles(self.train_path)
@@ -101,9 +102,9 @@ def generate(self):
101102
self.gen_dataset(self.train_files, train_dest_dir,
102103
self.coco_train_json, mode='train')
103104

104-
# val_dest_dir = Path(self.dst) / self.coco_val
105-
# self.gen_dataset(self.valid_files, val_dest_dir,
106-
# self.coco_val_json, mode='val')
105+
val_dest_dir = Path(self.dst) / self.coco_val
106+
self.gen_dataset(self.valid_files, val_dest_dir,
107+
self.coco_val_json, mode='val')
107108

108109
print(f"The output directory is: {str(self.dst)}")
109110

0 commit comments

Comments
 (0)