-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
37 lines (24 loc) · 831 Bytes
/
utils.py
File metadata and controls
37 lines (24 loc) · 831 Bytes
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
import os
import torch
import argparse
import numpy as np
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument('--res_dir', type=str, default='./')
args = parser.parse_args()
def get_device():
if torch.cuda.is_available():
device = torch.device('cuda:0')
else:
device = torch.device('cpu')
print('Using device: ', device)
return device
def get_wandb_key():
return os.environ['WANDB_API_KEY'] if 'WANDB_API_KEY' in os.environ else None
def get_res_path():
return args.res_dir
def calc_inv_density_score(x, knn):
return np.mean(knn.kneighbors(x.reshape(1, -1))[0])
# init save directories
Path(os.path.join(get_res_path(), 'plots')).mkdir(exist_ok=True, parents=True)
Path(os.path.join(get_res_path(), 'loaders')).mkdir(exist_ok=True, parents=True)