in anticipation/anticipation/datasets/epic_future_labels.py [0:0]
def __init__(self, ann_file, label, test_mode, task, dset, train_timestamps, val_timestamps, train_many_shot=False, **kwargs):
self.test_mode = test_mode
self.ann_file = ann_file
self.label = label
self.task = task
self.dset = dset
self.train_many_shot = train_many_shot
self.train_timestamps = train_timestamps
self.val_timestamps = val_timestamps
self.fps = 60 if self.dset=='epic' else 24
if self.dset == 'epic':
manyshot_verbs = sorted(epic_utils.get_many_shot("data/epic/annotations/EPIC_many_shot_verbs.csv"))
manyshot_nouns = sorted(epic_utils.get_many_shot("data/epic/annotations/EPIC_many_shot_nouns.csv"))
if train_many_shot:
self.num_verbs, self.num_nouns, self.num_actions = len(manyshot_verbs), len(manyshot_nouns), 250
else:
self.num_verbs, self.num_nouns, self.num_actions = 125, 352, 250
self.manyshot_verbs, self.manyshot_nouns = manyshot_verbs, manyshot_nouns
elif self.dset=='gtea':
manyshot_verbs = sorted(epic_utils.get_many_shot("data/gtea/annotations/gtea_many_shot_verbs.csv"))
manyshot_nouns = sorted(epic_utils.get_many_shot("data/gtea/annotations/gtea_many_shot_nouns.csv"))
if train_many_shot:
self.num_verbs, self.num_nouns, self.num_actions = len(manyshot_verbs), len(manyshot_nouns), 106
else:
self.num_verbs, self.num_nouns, self.num_actions = 19, 53, 106
# self.num_verbs, self.num_nouns, self.num_actions = 19, 53, 106
# find the most frequent 250 actions we're interested in predicting
records = [EpicRawFramesRecord(x.strip().split('\t')) for x in open(self.ann_file)]
int_counts = [(record.label[0], record.label[1]) for record in records]
int_counts = collections.Counter(int_counts).items()
int_counts = sorted(int_counts, key=lambda x: -x[1])[0:self.num_actions]
self.int_to_idx = {interact:idx for idx, (interact, count) in enumerate(int_counts)}
if task=='anticipation':
self.data = self.load_annotations_anticipation(ann_file)
elif task=='recognition':
self.data = self.load_annotations_recognition(ann_file)
if train_many_shot:
for record in self.data:
record.verbs = [manyshot_verbs.index(x) for x in record.verbs if x in manyshot_verbs]
record.nouns = [manyshot_nouns.index(x) for x in record.nouns if x in manyshot_nouns]
self.flag = np.ones(len(self), dtype=np.uint8) # just for mmaction sampler interface
# Only a few nouns/ints will actually have gt positives
# Pass these as part of the batch to evaluate mAP
# Don't know how to pass these in the config
eval_ints = set()
for record in self.data:
eval_ints |= set(record.ints)
eval_set = torch.zeros(1, self.num_actions)
eval_set[0, list(eval_ints)] = 1
self.eval_ints = eval_set.byte()
eval_nouns = set()
for record in self.data:
eval_nouns |= set(record.nouns)
if train_many_shot:# or self.dset != 'epic':
eval_set = torch.zeros(1, self.num_nouns)
eval_set[0, list(eval_nouns)] = 1
else:
eval_set = torch.zeros(3, self.num_nouns)
eval_set[0, list(eval_nouns)] = 1
manyshot = eval_nouns & set(manyshot_nouns)
rareshot = eval_nouns - set(manyshot_nouns)
eval_set[1, list(manyshot)] = 1
eval_set[2, list(rareshot)] = 1
self.eval_nouns = eval_set.byte()
eval_verbs = set()
for record in self.data:
eval_verbs |= set(record.verbs)
if train_many_shot:# or self.dset != 'epic':
eval_set = torch.zeros(1, self.num_verbs)
eval_set[0, list(eval_verbs)] = 1
else:
eval_set = torch.zeros(3, self.num_verbs)
eval_set[0, list(eval_verbs)] = 1
manyshot = eval_verbs & set(manyshot_verbs)
rareshot = eval_verbs - set(manyshot_verbs)
eval_set[1, list(manyshot)] = 1
eval_set[2, list(rareshot)] = 1
self.eval_verbs = eval_set.byte()