diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-12-15 21:32:51 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-12-15 21:32:51 +0100 |
| commit | e0b0b2f976c61225a178c7715caf2656a1f6741f (patch) | |
| tree | 78a0e5c861462822d212c065f0825c906209bfe9 /old/faiss/util.py | |
| parent | c5b02ffab8d388e8a2925e51736b902a48a95e71 (diff) | |
moving stuff
Diffstat (limited to 'old/faiss/util.py')
| -rw-r--r-- | old/faiss/util.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/old/faiss/util.py b/old/faiss/util.py new file mode 100644 index 00000000..97afbc22 --- /dev/null +++ b/old/faiss/util.py @@ -0,0 +1,29 @@ +import time +import simplejson as json +import pickle +from os import path +from collections import namedtuple + +# Converts JSON el['key'] to Pythonic object-style el.key +def _json_object_hook(d): + return namedtuple('X', d.keys())(*d.values()) + +# Load a JSON recipe +def load_recipe(path): + with open(path) as fh: + return json.load(fh, object_hook=_json_object_hook) + +# Load a pickle file +def load_pickle(data_dir, pkl_fn): + load_start = time.time() + with open(path.join(str(data_dir), str(pkl_fn)), 'rb') as fh: + raw = fh.read() + data = pickle.loads(raw) + load_end = time.time() + load_time = load_end - load_start + print("Pickle load time: {:.1f}s".format(load_time)) + return data + +def read_json(fn): + with open(fn, 'r') as json_file: + return json.load(json_file) |
