in anticipation/anticipation/datasets/epic_future_labels.py [0:0]
def load_annotations_recognition(self, ann_file):
vid_lengths = open(self.ann_file.replace('.csv', '_nframes.csv')).read().strip().split('\n')
vid_lengths = [line.split('\t') for line in vid_lengths]
vid_lengths = {k:int(v) for k,v in vid_lengths}
records = [EpicRawFramesRecord(x.strip().split('\t')) for x in open(ann_file)]
records_by_vid = collections.defaultdict(list)
for record in records:
record.uid = '%s_%s_%s'%(record.path, record.start_frame, record.end_frame)
records_by_vid[record.path].append(record)
records = []
for vid in records_by_vid:
vrecords = sorted(records_by_vid[vid], key=lambda record: record.end_frame)
length = vid_lengths[vid]
if self.test_mode:
timestamps = self.val_timestamps # 0.5, 0.75, 1.0]
else:
timestamps = self.train_timestamps # 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
timestamps = [int(frac*length) for frac in timestamps]
for i, t in enumerate(timestamps):
past_records = [record for record in vrecords if record.end_frame<=t]
if len(past_records)<3:
continue
record = EpicRawFramesRecord([vid, 0, t, -1, -1])
record.verbs = sorted(set([record.label[0] for record in past_records]))
record.nouns = sorted(set([record.label[1] for record in past_records]))
record.ints = sorted(set([self.int_to_idx[(record.label[0], record.label[1])] for record in past_records if (record.label[0], record.label[1]) in self.int_to_idx]))
record.ratio_idx = i
records.append(record)
print ('(REC) Collected %d records'%len(records))
return records