From 47bf1730fa9217a2682ef727347520c4e3cba98b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 9 Jul 2020 13:45:55 -0700 Subject: [PATCH] Update datasets.py --- utils/datasets.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index 0d8852c..bd42bc0 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -281,21 +281,19 @@ class LoadImagesAndLabels(Dataset): # for training/testing cache_images=False, single_cls=False, stride=32, pad=0.0): try: f = [] - for subpath in path if isinstance(path, list) else [path]: - subpath = str(Path(subpath)) # os-agnostic - parent = str(Path(subpath).parent) + os.sep - if os.path.isfile(subpath): # file - with open(subpath, 'r') as t: + for p in path if isinstance(path, list) else [path]: + p = str(Path(p)) # os-agnostic + parent = str(Path(p).parent) + os.sep + if os.path.isfile(p): # file + with open(p, 'r') as t: t = t.read().splitlines() - t = [x.replace('./', parent) if x.startswith('./') else x for x in t] # local to global path - f += t - elif os.path.isdir(subpath): # folder - f = glob.iglob(subpath + os.sep + '*.*') - # Maybe change this to f += glob.glob, this should allow handling also multiple folders + f += [x.replace('./', parent) if x.startswith('./') else x for x in t] # local to global path + elif os.path.isdir(p): # folder + f += glob.iglob(p + os.sep + '*.*') else: - raise Exception('%s does not exist' % subpath) + raise Exception('%s does not exist' % p) + path = p # *.npy dir self.img_files = [x.replace('/', os.sep) for x in f if os.path.splitext(x)[-1].lower() in img_formats] - path = subpath except: # Maybe avoid handling bare exceptions raise Exception('Error loading data from %s. See %s' % (path, help_url))