Cache v0.4 update (#3954)
Browse files- utils/datasets.py +8 -8
utils/datasets.py
CHANGED
@@ -397,12 +397,11 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|
397 |
|
398 |
# Check cache
|
399 |
self.label_files = img2label_paths(self.img_files) # labels
|
400 |
-
cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache')
|
401 |
-
|
402 |
-
cache, exists =
|
403 |
-
|
404 |
-
|
405 |
-
else:
|
406 |
cache, exists = self.cache_labels(cache_path, prefix), False # cache
|
407 |
|
408 |
# Display cache
|
@@ -496,9 +495,10 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|
496 |
x['hash'] = get_hash(self.label_files + self.img_files)
|
497 |
x['results'] = nf, nm, ne, nc, len(self.img_files)
|
498 |
x['msgs'] = msgs # warnings
|
499 |
-
x['version'] = 0.
|
500 |
try:
|
501 |
-
|
|
|
502 |
logging.info(f'{prefix}New cache created: {path}')
|
503 |
except Exception as e:
|
504 |
logging.info(f'{prefix}WARNING: Cache directory {path.parent} is not writeable: {e}') # path not writeable
|
|
|
397 |
|
398 |
# Check cache
|
399 |
self.label_files = img2label_paths(self.img_files) # labels
|
400 |
+
cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache')
|
401 |
+
try:
|
402 |
+
cache, exists = np.load(cache_path, allow_pickle=True).item(), True # load dict
|
403 |
+
assert cache['version'] == 0.4 and cache['hash'] == get_hash(self.label_files + self.img_files)
|
404 |
+
except:
|
|
|
405 |
cache, exists = self.cache_labels(cache_path, prefix), False # cache
|
406 |
|
407 |
# Display cache
|
|
|
495 |
x['hash'] = get_hash(self.label_files + self.img_files)
|
496 |
x['results'] = nf, nm, ne, nc, len(self.img_files)
|
497 |
x['msgs'] = msgs # warnings
|
498 |
+
x['version'] = 0.4 # cache version
|
499 |
try:
|
500 |
+
np.save(path, x) # save cache for next time
|
501 |
+
path.with_suffix('.cache.npy').rename(path) # remove .npy suffix
|
502 |
logging.info(f'{prefix}New cache created: {path}')
|
503 |
except Exception as e:
|
504 |
logging.info(f'{prefix}WARNING: Cache directory {path.parent} is not writeable: {e}') # path not writeable
|