@@ -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