-
Notifications
You must be signed in to change notification settings - Fork 5
/
dataset.py
64 lines (45 loc) · 1.58 KB
/
dataset.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import torch.utils.data as data
import os
import numpy as np
class FeatureRecord(object):
def __init__(self, row):
self._data = row
@property
def path_better(self):
return self._data[0]
@property
def path_worse(self):
return self._data[1]
class SkillDataSet(data.Dataset):
def __init__(self, root_path, list_file, ftr_tmpl='{}_{}.npz'):
self.root_path = root_path
self.list_file = list_file
self.ftr_tmpl = ftr_tmpl
self._parse_list()
def _load_features(self, vid):
features = np.load(os.path.join(self.root_path, self.ftr_tmpl.format(vid,'rgb')))['arr_0'].astype(np.float32)
return features
def _parse_list(self):
self.pair_list = [FeatureRecord(x.strip().split(' ')) for x in open(self.list_file)]
def __getitem__(self, index):
record = self.pair_list[index]
return self.get(record)
def get(self, record):
vid1 = self._load_features(record.path_better)
vid2 = self._load_features(record.path_worse)
return vid1, vid2
def __len__(self):
return len(self.pair_list)
class FeatureRecordSingle(object):
def __init__(self, row):
self._data = row
@property
def path(self):
return self._data[0]
class SkillDataSetSingle(SkillDataSet):
def _parse_list(self):
self.pair_list = [FeatureRecordSingle(x.strip().split(' ')) for x in open(self.list_file)]
def get(self, record):
vid = self._load_features(record.path)
name = record.path.split('/')[-1]
return name, vid