Views
No views yet
./checkpoints):.assets; thermal and depth need to be converted into greyscale1import torchvision.transforms as transforms
2
3# Define a transform to convert RGB images to single-channel
4to_single_channel = transforms.Compose([
5 transforms.Grayscale(num_output_channels=1),
6 transforms.Resize((224, 224)),
7 transforms.ToTensor(),
8])
9
10inputs = {
11 ModalityType.TEXT: data.load_and_transform_text(texts, device),
12 ModalityType.VISION: data.load_and_transform_vision_data(image_paths, device),
13 ModalityType.AUDIO: data.load_and_transform_audio_data(audio_paths, device),
14 ModalityType.DEPTH: torch.stack([to_single_channel(Image.open(path)) for path in depth_paths]).to(device),
15 ModalityType.THERMAL: torch.stack([to_single_channel(Image.open(path)) for path in thermal_paths]).to(device),
16}
17...
| Model | IN1k | K400 | NYU-D | ESC | LLVIP | Ego4D | download |
|---|---|---|---|---|---|---|---|
| imagebind_huge | 77.7 | 50.0 | 54.0 | 66.9 | 63.4 | 25.0 | checkpoint |
1conda create --name imagebind python=3.10 -y
2conda activate imagebind
3
4pip install .soundfile for reading/writing audio files. (Thanks @congyue1977)pip install soundfile1from imagebind import data
2import torch
3from imagebind.models import imagebind_model
4from imagebind.models.imagebind_model import ModalityType
5
6text_list=["A dog.", "A car", "A bird"]
7image_paths=[".assets/dog_image.jpg", ".assets/car_image.jpg", ".assets/bird_image.jpg"]
8audio_paths=[".assets/dog_audio.wav", ".assets/car_audio.wav", ".assets/bird_audio.wav"]
9
10device = "cuda:0" if torch.cuda.is_available() else "cpu"
11
12# Instantiate model
13model = imagebind_model.imagebind_huge(pretrained=True)
14model.eval()
15model.to(device)
16
17# Load data
18inputs = {
19 ModalityType.TEXT: data.load_and_transform_text(text_list, device),
20 ModalityType.VISION: data.load_and_transform_vision_data(image_paths, device),
21 ModalityType.AUDIO: data.load_and_transform_audio_data(audio_paths, device),
22}
23
24with torch.no_grad():
25 embeddings = model(inputs)
26
27print(
28 "Vision x Text: ",
29 torch.softmax(embeddings[ModalityType.VISION] @ embeddings[ModalityType.TEXT].T, dim=-1),
30)
31print(
32 "Audio x Text: ",
33 torch.softmax(embeddings[ModalityType.AUDIO] @ embeddings[ModalityType.TEXT].T, dim=-1),
34)
35print(
36 "Vision x Audio: ",
37 torch.softmax(embeddings[ModalityType.VISION] @ embeddings[ModalityType.AUDIO].T, dim=-1),
38)
39
40# Expected output:
41#
42# Vision x Text:
43# tensor([[9.9761e-01, 2.3694e-03, 1.8612e-05],
44# [3.3836e-05, 9.9994e-01, 2.4118e-05],
45# [4.7997e-05, 1.3496e-02, 9.8646e-01]])
46#
47# Audio x Text:
48# tensor([[1., 0., 0.],
49# [0., 1., 0.],
50# [0., 0., 1.]])
51#
52# Vision x Audio:
53# tensor([[0.8070, 0.1088, 0.0842],
54# [0.1036, 0.7884, 0.1079],
55# [0.0018, 0.0022, 0.9960]])
56@inproceedings{girdhar2023imagebind,
title={ImageBind: One Embedding Space To Bind Them All},
author={Girdhar, Rohit and El-Nouby, Alaaeldin and Liu, Zhuang
and Singh, Mannat and Alwala, Kalyan Vasudev and Joulin, Armand and Misra, Ishan},
booktitle={CVPR},
year={2023}
}