glenn-jocher
commited on
Commit
•
4fdaec0
1
Parent(s):
fe39562
Single `cache_version` definition (#4846)
Browse filesDefines dataset labels *.cache version in a single place, fixing a bug introduced in #4845.
- utils/datasets.py +5 -2
utils/datasets.py
CHANGED
@@ -365,6 +365,8 @@ def img2label_paths(img_paths):
|
|
365 |
|
366 |
|
367 |
class LoadImagesAndLabels(Dataset): # for training/testing
|
|
|
|
|
368 |
def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, rect=False, image_weights=False,
|
369 |
cache_images=False, single_cls=False, stride=32, pad=0.0, prefix=''):
|
370 |
self.img_size = img_size
|
@@ -404,7 +406,8 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|
404 |
cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache')
|
405 |
try:
|
406 |
cache, exists = np.load(cache_path, allow_pickle=True).item(), True # load dict
|
407 |
-
assert cache['version'] ==
|
|
|
408 |
except:
|
409 |
cache, exists = self.cache_labels(cache_path, prefix), False # cache
|
410 |
|
@@ -508,7 +511,7 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|
508 |
x['hash'] = get_hash(self.label_files + self.img_files)
|
509 |
x['results'] = nf, nm, ne, nc, len(self.img_files)
|
510 |
x['msgs'] = msgs # warnings
|
511 |
-
x['version'] =
|
512 |
try:
|
513 |
np.save(path, x) # save cache for next time
|
514 |
path.with_suffix('.cache.npy').rename(path) # remove .npy suffix
|
|
|
365 |
|
366 |
|
367 |
class LoadImagesAndLabels(Dataset): # for training/testing
|
368 |
+
cache_version = 0.5 # dataset labels *.cache version
|
369 |
+
|
370 |
def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, rect=False, image_weights=False,
|
371 |
cache_images=False, single_cls=False, stride=32, pad=0.0, prefix=''):
|
372 |
self.img_size = img_size
|
|
|
406 |
cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache')
|
407 |
try:
|
408 |
cache, exists = np.load(cache_path, allow_pickle=True).item(), True # load dict
|
409 |
+
assert cache['version'] == self.cache_version # same version
|
410 |
+
assert cache['hash'] == get_hash(self.label_files + self.img_files) # same hash
|
411 |
except:
|
412 |
cache, exists = self.cache_labels(cache_path, prefix), False # cache
|
413 |
|
|
|
511 |
x['hash'] = get_hash(self.label_files + self.img_files)
|
512 |
x['results'] = nf, nm, ne, nc, len(self.img_files)
|
513 |
x['msgs'] = msgs # warnings
|
514 |
+
x['version'] = self.cache_version # cache version
|
515 |
try:
|
516 |
np.save(path, x) # save cache for next time
|
517 |
path.with_suffix('.cache.npy').rename(path) # remove .npy suffix
|