-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
65 lines (45 loc) · 1.16 KB
/
utils.py
File metadata and controls
65 lines (45 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import gzip
import pickle
import os
import glob
# util
import yaml
import imageio
def slurpjson(fn):
import json
with open(fn, 'r') as f:
return json.load(f)
def mkdir(path):
if not os.path.isdir(path):
os.mkdir(path)
return path
def mdir(path):
try:
os.makedirs(path)
# print("Directory ", path, " Created ")
except FileExistsError:
print("Directory ", path, " already exists")
def save(fn, a):
with gzip.open(fn, 'wb', compresslevel=2) as f:
pickle.dump(a, f, 2)
def imsave(fn, img):
imageio.imwrite(fn, img)
def load(fn):
with gzip.open(fn, 'rb') as f:
return pickle.load(f)
def spit_json(fn, data):
import json
with open(fn, 'w') as outfile:
json.dump(data, outfile)
def read_file(file_path):
"""
Loads file content into Python object representation.
Args:
file_path: path to YAML file.
Returns: dictionary representing YAML content
"""
with open(file_path, 'r', encoding='utf-8') as f:
loader = yaml.Loader(f)
return loader.get_single_data()
def get_all_folder(path):
return glob.glob('{}/*'.format(path))