-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
46 lines (37 loc) · 969 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
37
38
39
40
41
42
43
44
45
import numpy as np
import os
class average_meter:
def __init__(self):
self.value = 0
self.avg = 0
self.sum = 0
self.count = 0
self.reset()
def reset(self):
self.value = 0
self.avg = 0
self.sum = 0
self.count = 0
def update(self, val, n=1):
self.value = val
self.sum += val * n
self.count += n
self.avg = self.sum / self.count
@property
def val(self):
return self.avg
def get_mnist_index(target, one_class_label):
train_indices = []
test_indices = []
for i in range(len(target)):
if target[i] == one_class_label:
train_indices.append(i)
else:
test_indices.append(i)
return train_indices, test_indices
def make_dir(dir_name):
if not os.path.exists(dir_name):
os.makedirs(dir_name)
print("Directory " , dir_name , " Created ")
else:
pass