Single `cache_version` definition (#4846)
Defines dataset labels *.cache version in a single place, fixing a bug introduced in #4845.pull/4849/head
parent
fe39562a5f
commit
4fdaec0449
utils
|
@ -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 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|||
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 @@ class LoadImagesAndLabels(Dataset): # for training/testing
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue