def parse_annotations()

in build_graph/data/epic.py [0:0]


def parse_annotations(data_dir):

    # get the list of object and action classes
    with open(f'{data_dir}/annotations/EPIC_verb_classes.csv') as f:
        verbs = f.read().strip().split('\n')[1:]
        verbs = [line.split(',')[1] for line in verbs]
    with open(f'{data_dir}/annotations/EPIC_noun_classes.csv') as f:
        nouns = f.read().strip().split('\n')[1:]
        nouns = [line.split(',')[1] for line in nouns]

    annotations = {'nouns':nouns, 'verbs':verbs}

    # parse the interactions
    interactions = []
    interaction_labels = open(f'{data_dir}/annotations/EPIC_train_action_labels.csv').read().strip().split('\n')[1:]
    for line in interaction_labels:
        split = line.split(',')
        v_id = split[2]
        start_time, stop_time, start, stop = split[4:8]
        verb, verb_class, noun, noun_class = split[8:12]
        interactions.append({'v_id':v_id, 'start_time':start_time, 'stop_time':stop_time, 'start':int(start), 'stop':int(stop), 'verb':int(verb_class), 'noun':int(noun_class)})
    annotations['interactions'] = interactions

    videos = set([entry['v_id'] for entry in interactions])
    annotations['videos'] = sorted(videos)

    # S1: Seen Kitchens split - 80:20 split for train/val
    vid_by_person = collections.defaultdict(list)
    for v_id in videos:
        vid_by_person[v_id.split('_')[0]].append(v_id)

    train_vids, val_vids = [], []
    for person in vid_by_person:
        vids = sorted(vid_by_person[person])
        offset = int(0.8*len(vids))
        train_vids += vids[:offset]
        val_vids += vids[offset:]
        
    annotations.update({'train_vids':train_vids, 'val_vids':val_vids})


    video_lengths = collections.defaultdict(int)
    for entry in interactions:
        video_lengths[entry['v_id']] = max(video_lengths[entry['v_id']], entry['stop'])
    annotations['vid_lengths'] = video_lengths

    torch.save(annotations, 'build_graph/data/epic/epic_data.pth')