From 2116285dfd1fdbb38bd97492966e09174aae03c8 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 17 Sep 2021 17:53:00 +0200 Subject: [PATCH] Single cache_version definition Defines dataset labels *.cache version in a single place, fixing a bug introduced in #4845. --- utils/datasets.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/datasets.py b/utils/datasets.py index adcdafe69df7..d253cb177b82 100755 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -365,6 +365,8 @@ def img2label_paths(img_paths): class LoadImagesAndLabels(Dataset): # for training/testing + cache_version = 0.5 # dataset labels *.cache version + def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, rect=False, image_weights=False, cache_images=False, single_cls=False, stride=32, pad=0.0, prefix=''): self.img_size = img_size @@ -404,7 +406,8 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache') try: cache, exists = np.load(cache_path, allow_pickle=True).item(), True # load dict - assert cache['version'] == 0.4 and cache['hash'] == get_hash(self.label_files + self.img_files) + assert cache['version'] == self.cache_version # same version + assert cache['hash'] == get_hash(self.label_files + self.img_files) # same hash except: cache, exists = self.cache_labels(cache_path, prefix), False # cache @@ -508,7 +511,7 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''): x['hash'] = get_hash(self.label_files + self.img_files) x['results'] = nf, nm, ne, nc, len(self.img_files) x['msgs'] = msgs # warnings - x['version'] = 0.5 # cache version + x['version'] = self.cache_version # cache version try: np.save(path, x) # save cache for next time path.with_suffix('.cache.npy').rename(path) # remove .npy suffix