From 9cbc2591ad04a909fdf6411d0c0ecace50f0a02d Mon Sep 17 00:00:00 2001 From: SunAhong1993 <48579383+SunAhong1993@users.noreply.github.com> Date: Thu, 26 Dec 2019 21:21:03 +0800 Subject: [PATCH] Update x2coco.py (#135) --- ppdet/data/tools/x2coco.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ppdet/data/tools/x2coco.py b/ppdet/data/tools/x2coco.py index 4d743c926..dec0e2359 100644 --- a/ppdet/data/tools/x2coco.py +++ b/ppdet/data/tools/x2coco.py @@ -227,7 +227,8 @@ def main(): print('The image folder does not exist!') os._exit(0) try: - assert args.train_proportion + args.val_proportion + args.test_proportion == 1.0 + assert abs(args.train_proportion + args.val_proportion \ + + args.test_proportion - 1.0) < 1e-5 except AssertionError as e: print( 'The sum of pqoportion of training, validation and test datase must be 1!' @@ -255,18 +256,21 @@ def main(): count = 1 for img_name in os.listdir(args.image_input_dir): if count <= train_num: - shutil.copyfile( - osp.join(args.image_input_dir, img_name), - osp.join(args.output_dir + '/train/', img_name)) - else: - if count <= train_num + val_num: + if osp.exists(args.output_dir + '/train/'): shutil.copyfile( osp.join(args.image_input_dir, img_name), - osp.join(args.output_dir + '/val/', img_name)) + osp.join(args.output_dir + '/train/', img_name)) + else: + if count <= train_num + val_num: + if osp.exists(args.output_dir + '/val/'): + shutil.copyfile( + osp.join(args.image_input_dir, img_name), + osp.join(args.output_dir + '/val/', img_name)) else: - shutil.copyfile( - osp.join(args.image_input_dir, img_name), - osp.join(args.output_dir + '/test/', img_name)) + if osp.exists(args.output_dir + '/test/'): + shutil.copyfile( + osp.join(args.image_input_dir, img_name), + osp.join(args.output_dir + '/test/', img_name)) count = count + 1 # Deal with the json files. -- GitLab