Offline Datasets res net optionality

This commit is contained in:
Si11ium
2020-03-12 18:32:23 +01:00
parent 2f99341cc3
commit bb47e07566
11 changed files with 638 additions and 140 deletions

22
lib/utils/tools.py Normal file
View File

@@ -0,0 +1,22 @@
import pickle
import shelve
from pathlib import Path
def write_to_shelve(file_path, value):
check_path(file_path)
file_path.parent.mkdir(exist_ok=True, parents=True)
with shelve.open(str(file_path), protocol=pickle.HIGHEST_PROTOCOL) as f:
new_key = str(len(f))
f[new_key] = value
def load_from_shelve(file_path, key):
check_path(file_path)
with shelve.open(str(file_path)) as d:
return d[key]
def check_path(file_path):
assert isinstance(file_path, Path)
assert str(file_path).endswith('.pik')