Unverified 提交 443af8b2 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Cache v0.4 update (#3954)

上级 a26e7de2
...@@ -397,12 +397,11 @@ class LoadImagesAndLabels(Dataset): # for training/testing ...@@ -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 ...@@ -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
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论