glenn-jocher commited on
Commit
dd8e742
·
unverified ·
2 Parent(s): 2110f5e dd33d2a

Merge pull request #334 from lorenzomammana/feature-multiple-datasets-training

Browse files
Files changed (1) hide show
  1. utils/datasets.py +15 -12
utils/datasets.py CHANGED
@@ -280,19 +280,22 @@ class LoadImagesAndLabels(Dataset): # for training/testing
280
  def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, rect=False, image_weights=False,
281
  cache_images=False, single_cls=False, stride=32, pad=0.0):
282
  try:
283
- path = str(Path(path)) # os-agnostic
284
- parent = str(Path(path).parent) + os.sep
285
- if os.path.isfile(path): # file
286
- with open(path, 'r') as f:
287
- f = f.read().splitlines()
288
- f = [x.replace('./', parent) if x.startswith('./') else x for x in f] # local to global path
289
- elif os.path.isdir(path): # folder
290
- f = glob.iglob(path + os.sep + '*.*')
291
- else:
292
- raise Exception('%s does not exist' % path)
 
 
 
293
  self.img_files = [x.replace('/', os.sep) for x in f if os.path.splitext(x)[-1].lower() in img_formats]
294
- except:
295
- raise Exception('Error loading data from %s. See %s' % (path, help_url))
296
 
297
  n = len(self.img_files)
298
  assert n > 0, 'No images found in %s. See %s' % (path, help_url)
 
280
  def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, rect=False, image_weights=False,
281
  cache_images=False, single_cls=False, stride=32, pad=0.0):
282
  try:
283
+ f = []
284
+ for p in path if isinstance(path, list) else [path]:
285
+ p = str(Path(p)) # os-agnostic
286
+ parent = str(Path(p).parent) + os.sep
287
+ if os.path.isfile(p): # file
288
+ with open(p, 'r') as t:
289
+ t = t.read().splitlines()
290
+ f += [x.replace('./', parent) if x.startswith('./') else x for x in t] # local to global path
291
+ elif os.path.isdir(p): # folder
292
+ f += glob.iglob(p + os.sep + '*.*')
293
+ else:
294
+ raise Exception('%s does not exist' % p)
295
+ path = p # *.npy dir
296
  self.img_files = [x.replace('/', os.sep) for x in f if os.path.splitext(x)[-1].lower() in img_formats]
297
+ except Exception as e:
298
+ raise Exception('Error loading data from %s: %s\nSee %s' % (path, e, help_url))
299
 
300
  n = len(self.img_files)
301
  assert n > 0, 'No images found in %s. See %s' % (path, help_url)