-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
36 lines (29 loc) · 868 Bytes
/
utils.py
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
import torch
import pickle
from munch import Munch, munchify
import yaml
def get_device():
if torch.cuda.is_available():
device = torch.device('cuda')
elif torch.backends.mps.is_available():
device = torch.device('mps')
else:
device = torch.device('cpu')
return device
def save_pkl(filename, save_object):
writer = open(filename,'wb')
pickle.dump(save_object, writer)
writer.close()
def load_pkl(filename):
loader = open(filename,'rb')
file = pickle.load(loader)
loader.close()
return file
def load_config(config_path) -> Munch:
try:
with open(config_path, 'r') as configuration_fstream:
yaml_dict = yaml.safe_load(configuration_fstream)
return munchify(yaml_dict)
except FileNotFoundError:
print("Error with config file")
raise FileNotFoundError