Skip to content

Commit a43d6f3

Browse files
committed
Fix the bug when the label txt is empty by using the labelImg
1 parent de6a4f3 commit a43d6f3

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
│   ├── images4.txt
6161
│   ├── images5.txt
6262
│   └── images7.txt
63-
├── non_labels # 这是没有标注图像的目录
63+
├── non_labels # 这是没有标注图像的目录,自行决定如何处置
6464
│   └── images6.jpg
6565
├── test.txt
6666
├── train.txt

labelImg_2_yolov5.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ def __init__(self, root_dir, out_dir, val_ratio, have_test, test_ratio):
1313
self.root_dir = Path(root_dir)
1414
self.verify_exists(self.root_dir)
1515

16-
self.classes_path = self.root_dir / 'classes.txt'
17-
self.verify_exists(self.classes_path)
18-
1916
self.out_dir = Path(out_dir)
2017
self.out_img_dir = self.out_dir / 'images'
2118
self.out_label_dir = self.out_dir / 'labels'
2219
self.out_non_label_dir = self.out_dir / 'non_labels'
2320

21+
self.classes_path = self.root_dir / 'classes.txt'
22+
self.verify_exists(self.classes_path)
23+
self.cp_file(self.classes_path, dst_dir=self.out_dir)
24+
2425
self.val_ratio = val_ratio
2526
self.have_test = have_test
2627
self.test_ratio = test_ratio
@@ -41,7 +42,6 @@ def __call__(self):
4142
self.write_txt(self.out_dir / 'val.txt', val_list)
4243
if test_list:
4344
self.write_txt(self.out_dir / 'test.txt', test_list)
44-
self.cp_file(self.classes_path, dst_dir=self.out_dir)
4545

4646
@staticmethod
4747
def verify_exists(file_path):
@@ -62,7 +62,8 @@ def gen_image_label_dir(self, img_list):
6262
new_image_list = []
6363
for img_path in img_list:
6464
right_label_path = img_path.with_name(f'{img_path.stem}.txt')
65-
if right_label_path.exists():
65+
if right_label_path.exists() \
66+
and self.read_txt(str(right_label_path)):
6667
self.cp_file(img_path, dst_dir=self.out_img_dir)
6768
self.cp_file(right_label_path, dst_dir=self.out_label_dir)
6869

0 commit comments

Comments
 (0)