lorenzomammana
commited on
Commit
·
94342ac
1
Parent(s):
6b95d6d
Handle multiple datasets
Browse files- utils/datasets.py +21 -9
utils/datasets.py
CHANGED
@@ -280,16 +280,28 @@ 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 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
|
|
|
|
|
|
291 |
else:
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
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 |
+
if type(path) is list:
|
284 |
+
# Multiple datasets handler
|
285 |
+
f = []
|
286 |
+
for subpath in path:
|
287 |
+
with open(subpath, 'r') as t:
|
288 |
+
subpath = str(Path(subpath)) # os-agnostic
|
289 |
+
parent = str(Path(subpath).parent) + os.sep
|
290 |
+
t = t.read().splitlines()
|
291 |
+
t = [x.replace('./', parent) if x.startswith('./') else x for x in t] # local to global path
|
292 |
+
f += t
|
293 |
+
path = str(Path(path[0])) # from now on treat multiple datasets as single
|
294 |
else:
|
295 |
+
path = str(Path(path)) # os-agnostic
|
296 |
+
parent = str(Path(path).parent) + os.sep
|
297 |
+
if os.path.isfile(path): # file
|
298 |
+
with open(path, 'r') as f:
|
299 |
+
f = f.read().splitlines()
|
300 |
+
f = [x.replace('./', parent) if x.startswith('./') else x for x in f] # local to global path
|
301 |
+
elif os.path.isdir(path): # folder
|
302 |
+
f = glob.iglob(path + os.sep + '*.*')
|
303 |
+
else:
|
304 |
+
raise Exception('%s does not exist' % path)
|
305 |
self.img_files = [x.replace('/', os.sep) for x in f if os.path.splitext(x)[-1].lower() in img_formats]
|
306 |
except:
|
307 |
raise Exception('Error loading data from %s. See %s' % (path, help_url))
|