| | from imagebind import data |
| | import torch |
| | from imagebind.models import imagebind_model |
| | from imagebind.models.imagebind_model import ModalityType |
| | import pandas as pd |
| | import os |
| |
|
| | import argparse |
| |
|
| | |
| | parser = argparse.ArgumentParser() |
| |
|
| | |
| | parser.add_argument('--data', type=str, default="./Vinoground", help='Path to Vinoground dataset (from Huggingface)') |
| |
|
| | |
| | args = parser.parse_args() |
| |
|
| | data_path = args.data |
| |
|
| | vino = pd.read_csv(os.path.join(data_path, "vinoground_hardest.csv")) |
| |
|
| | num_examples = len(vino.index) |
| |
|
| | |
| |
|
| | device = "cuda:0" if torch.cuda.is_available() else "cpu" |
| |
|
| | |
| | model = imagebind_model.imagebind_huge(True) |
| | model.eval() |
| | model.to(device) |
| |
|
| | text_correct = 0 |
| | video_correct = 0 |
| | group_correct = 0 |
| |
|
| | from tqdm import tqdm |
| | for row_num in tqdm(range(num_examples)): |
| | video_num = vino["index"][row_num] |
| | videos = [] |
| | texts = [] |
| | videos.append(os.path.join(data_path, f"vinoground_videos/{video_num}_pos.mp4")) |
| | videos.append(os.path.join(data_path, f"vinoground_videos/{video_num}_neg.mp4")) |
| | texts.append(vino["pos_cap"][row_num]) |
| | texts.append(vino["neg_cap"][row_num]) |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | inputs = { |
| | ModalityType.TEXT: data.load_and_transform_text(texts, device), |
| | ModalityType.VISION: data.load_and_transform_video_data(videos, device), |
| | } |
| |
|
| | with torch.no_grad(): |
| | embeddings = model(inputs) |
| |
|
| | results = embeddings[ModalityType.VISION] @ embeddings[ModalityType.TEXT].T |
| | |
| |
|
| | video_correct += results[0][0] > results[1][0] and results[1][1] > results[0][1] |
| | text_correct += results[0][0] > results[0][1] and results[1][1] > results[1][0] |
| | group_correct += results[0][0] > results[1][0] and results[1][1] > results[0][1] and results[0][0] > results[0][1] and results[1][1] > results[1][0] |
| | |
| | print(text_correct / num_examples, video_correct / num_examples, group_correct / num_examples) |