From c78d49f190c7ac2f5723f6a913aee39154106707 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 15 Jun 2020 12:25:48 -0700 Subject: [PATCH] check_file() update from yolov5 --- detect.py | 4 ++-- test.py | 4 ++-- train.py | 4 ++-- utils/utils.py | 10 ++++++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/detect.py b/detect.py index b52f7826..0c4b17b3 100644 --- a/detect.py +++ b/detect.py @@ -183,8 +183,8 @@ if __name__ == '__main__': parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS') parser.add_argument('--augment', action='store_true', help='augmented inference') opt = parser.parse_args() - opt.cfg = list(glob.iglob('./**/' + opt.cfg, recursive=True))[0] # find file - opt.names = list(glob.iglob('./**/' + opt.names, recursive=True))[0] # find file + opt.cfg = check_file(opt.cfg) # check file + opt.names = check_file(opt.names) # check file print(opt) with torch.no_grad(): diff --git a/test.py b/test.py index 5d313efa..ace09951 100644 --- a/test.py +++ b/test.py @@ -243,8 +243,8 @@ if __name__ == '__main__': parser.add_argument('--augment', action='store_true', help='augmented inference') opt = parser.parse_args() opt.save_json = opt.save_json or any([x in opt.data for x in ['coco.data', 'coco2014.data', 'coco2017.data']]) - opt.cfg = list(glob.iglob('./**/' + opt.cfg, recursive=True))[0] # find file - opt.data = list(glob.iglob('./**/' + opt.data, recursive=True))[0] # find file + opt.cfg = check_file(opt.cfg) # check file + opt.data = check_file(opt.data) # check file print(opt) # task = 'test', 'study', 'benchmark' diff --git a/train.py b/train.py index 8ea7ed28..f963fdf1 100644 --- a/train.py +++ b/train.py @@ -397,8 +397,8 @@ if __name__ == '__main__': opt = parser.parse_args() opt.weights = last if opt.resume else opt.weights check_git_status() - opt.cfg = list(glob.iglob('./**/' + opt.cfg, recursive=True))[0] # find file - # opt.data = list(glob.iglob('./**/' + opt.data, recursive=True))[0] # find file + opt.cfg = check_file(opt.cfg) # check file + opt.data = check_file(opt.data) # check file print(opt) opt.img_size.extend([opt.img_size[-1]] * (3 - len(opt.img_size))) # extend to 3 sizes (min, max, test) device = torch_utils.select_device(opt.device, apex=mixed_precision, batch_size=opt.batch_size) diff --git a/utils/utils.py b/utils/utils.py index bad2cf02..2643842d 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -43,6 +43,16 @@ def check_git_status(): print(s[s.find('Your branch is behind'):s.find('\n\n')] + '\n') +def check_file(file): + # Searches for file if not found locally + if os.path.isfile(file): + return file + else: + files = glob.glob('./**/' + file, recursive=True) # find file + assert len(files), 'File Not Found: %s' % file # assert file was found + return files[0] # return first file if multiple found + + def load_classes(path): # Loads *.names file at 'path' with open(path, 'r') as f: