Skip to content

Commit

Permalink
Single cache_version definition
Browse files Browse the repository at this point in the history
Defines dataset labels *.cache version in a single place, fixing a bug introduced in #4845.
  • Loading branch information
glenn-jocher committed Sep 17, 2021
1 parent fe39562 commit 2116285
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2116285

Please sign in to comment.