-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmisc.py
40 lines (30 loc) · 942 Bytes
/
misc.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
37
38
39
40
import os
import numpy as np
import torch
EPSILON = 1E-10
def init_env(cfg):
np.random.seed(cfg.seed)
torch.manual_seed(cfg.seed)
torch.backends.cudnn.benchmark = not cfg.not_cuda_benchmark
os.environ['CUDA_VISIBLE_DEVICES'] = cfg.gpus_str
cfg.device = torch.device('cuda' if cfg.gpus[0] >= 0 else 'cpu')
return cfg
def load_dataset(dataset_name):
if dataset_name.lower() == 'kitti':
from datasets.kitti import KITTI as Dataset
elif dataset_name.lower() == 'coco':
from datasets.coco import COCO as Dataset
else:
raise ValueError('invalid dataset name.')
return Dataset
class MetricLogger(object):
def __init__(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0
def update(self, val, n=1):
self.val = val
self.sum += val * n
self.count += n
self.avg = self.sum / (self.count + EPSILON)