facebookresearch / omnivore

Omnivore: A Single Model for Many Visual Modalities
Other
559 stars 39 forks source link

How can I get noun scores and verb scores? #42

Open anamanzano opened 1 year ago

anamanzano commented 1 year ago

Hi! So I was wondering if it's possible to get verb scores and noun scores from the action recognition scores. I was using margin probability to obtain the results, but I don't get anything that makes sense. Maybe I have to normalize the results? Or is something that I can not get from action scores? Thank you!

anamanzano commented 1 year ago

Does this code make sense?

  with torch.no_grad():
        prediction = model(video_input.to(device), input_type="video")

        # Get the predicted classes (action scores)
        pred_class_all = prediction.topk(k=3806)
        class_indices = pred_class_all.indices
        class_scores = pred_class_all.values

    pred_class_names_all = []
    for indices, score in zip(class_indices[0], class_scores[0]):
        pred_class_names_all.append((epic_id_to_action[int(indices)], score))

    verbs = []
    nouns = []
    verb_scores = []
    noun_scores = []
    dic_verbs = {}
    dic_nouns = {}

    for pred, score in pred_class_names_all:
        verb, noun = pred.split()
        verbs.append(verb)
        nouns.append(noun)
        verb_scores.append(score)
        noun_scores.append(score)

    # Split the predictions into verbs and nouns and store in separate dictionaries
    verb_scores_dict = {}
    noun_scores_dict = {}

    for pred, score in pred_class_names_all:
        verb, noun = pred.split()

        if verb in verb_scores_dict:
          verb_scores_dict[verb] += score
        else:
          verb_scores_dict[verb] = score

        if noun in noun_scores_dict:
          noun_scores_dict[noun] += score
        else:
          noun_scores_dict[noun] = score

Thank you!