-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
39 lines (29 loc) · 1.02 KB
/
utils.py
File metadata and controls
39 lines (29 loc) · 1.02 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
import os
import numpy as np
class AverageMeter(object):
"""Computes and stores the average and current value"""
def __init__(self, name):
self.name = name
self.reset()
def reset(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
def load_and_merge_npy_files(root_dir, label_file):
image_files = [f for f in os.listdir(root_dir) if f.endswith('.npy') and f != label_file]
labels = np.load(os.path.join(root_dir, label_file))
all_images = []
repeated_labels=[]
for img_file in image_files:
if img_file.startswith('snow'):
images = np.load(os.path.join(root_dir, img_file))
#print('images.shape',images.shape)
all_images.append(images)
repeated_labels.append(labels)
return np.concatenate(all_images), np.concatenate(repeated_labels),