Cache v0.4 update (#3954)

This commit is contained in:
Glenn Jocher 2021-07-10 14:18:46 +02:00 committed by GitHub
parent a26e7de2bf
commit 443af8b25a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -397,12 +397,11 @@ class LoadImagesAndLabels(Dataset): # for training/testing
# Check cache # Check cache
self.label_files = img2label_paths(self.img_files) # labels self.label_files = img2label_paths(self.img_files) # labels
cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache') # cached labels cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix('.cache')
if cache_path.is_file(): try:
cache, exists = torch.load(cache_path), True # load cache, exists = np.load(cache_path, allow_pickle=True).item(), True # load dict
if cache.get('version') != 0.3 or cache.get('hash') != get_hash(self.label_files + self.img_files): assert cache['version'] == 0.4 and cache['hash'] == get_hash(self.label_files + self.img_files)
cache, exists = self.cache_labels(cache_path, prefix), False # re-cache except:
else:
cache, exists = self.cache_labels(cache_path, prefix), False # cache cache, exists = self.cache_labels(cache_path, prefix), False # cache
# Display cache # Display cache
@ -496,9 +495,10 @@ class LoadImagesAndLabels(Dataset): # for training/testing
x['hash'] = get_hash(self.label_files + self.img_files) x['hash'] = get_hash(self.label_files + self.img_files)
x['results'] = nf, nm, ne, nc, len(self.img_files) x['results'] = nf, nm, ne, nc, len(self.img_files)
x['msgs'] = msgs # warnings x['msgs'] = msgs # warnings
x['version'] = 0.3 # cache version x['version'] = 0.4 # cache version
try: try:
torch.save(x, path) # save cache for next time np.save(path, x) # save cache for next time
path.with_suffix('.cache.npy').rename(path) # remove .npy suffix
logging.info(f'{prefix}New cache created: {path}') logging.info(f'{prefix}New cache created: {path}')
except Exception as e: except Exception as e:
logging.info(f'{prefix}WARNING: Cache directory {path.parent} is not writeable: {e}') # path not writeable logging.info(f'{prefix}WARNING: Cache directory {path.parent} is not writeable: {e}') # path not writeable