Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions tests/models/albef/test_albef.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,6 @@ def albef_model_output(albef_model):
return albef_model(image, text, text_atts)


def test_albef_image_embeddings(albef_model_output):
expected = Tensor(
[
[[1.364883, -1.003092, -0.361791], [-0.634884, 1.411830, -0.776947]],
[[1.401580, -0.537510, -0.864071], [1.378901, -0.417473, -0.961429]],
]
)
assert_expected(albef_model_output.image_embeddings, expected, rtol=0, atol=1e-4)


def test_albef_image_embeddings_momentum(albef_model_output):
expected = Tensor(
[
[[1.364883, -1.003092, -0.361791], [-0.634884, 1.411830, -0.776947]],
[[1.401580, -0.537510, -0.864070], [1.378902, -0.417473, -0.961429]],
]
)
assert_expected(albef_model_output.image_embeddings_m, expected, rtol=0, atol=1e-4)


def test_albef_text_embeddings(albef_model_output):
expected = Tensor(
[
Expand All @@ -119,30 +99,6 @@ def test_albef_text_embeddings_momentum(albef_model_output):
assert_expected(albef_model_output.text_embeddings_m, expected, rtol=0, atol=1e-4)


def test_albef_multimodal_embeddings(albef_model_output):
expected = Tensor(
[
[[-0.068738, 1.257666, -1.188928], [1.409873, -0.609056, -0.800817]],
[[-1.402520, 0.544084, 0.858435], [1.202279, -1.246038, 0.043760]],
]
)
assert_expected(
albef_model_output.multimodal_embeddings, expected, rtol=0, atol=1e-4
)


def test_albef_multimodal_embeddings_momentum(albef_model_output):
expected = Tensor(
[
[[-0.068738, 1.257666, -1.188928], [1.409873, -0.609056, -0.800817]],
[[-1.402520, 0.544084, 0.858435], [1.202279, -1.246038, 0.043760]],
]
)
assert_expected(
albef_model_output.multimodal_embeddings_m, expected, rtol=0, atol=1e-4
)


def test_copy_params_momentum_models():
model = nn.Linear(3, 2)
model_m = copy.deepcopy(model)
Expand Down
16 changes: 1 addition & 15 deletions tests/models/albef/test_image_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import pytest
import torch
from tests.test_utils import assert_expected, set_rng_seed
from torch import Tensor
from tests.test_utils import set_rng_seed
from torchmultimodal.models.albef.image_encoder import ALBEFVisionEncoder


Expand All @@ -24,19 +23,6 @@ class TestALBEFVisionEncoder:
mlp_dim=6,
)

def test_vision_transformer(self):
set_rng_seed(0)
vit = self.vision_encoder
input = torch.randn(1, 3, 4, 4)
output = vit(input)
expected = Tensor(
[
[1.399478, -0.875986, -0.523492],
[-0.869867, 1.400589, -0.530722],
]
).unsqueeze(0)
assert_expected(output, expected, rtol=0, atol=1e-4)

def test_invalid_input_length(self):
input = torch.randn(3, 4, 4)
with pytest.raises(IndexError, match="index out of range"):
Expand Down
84 changes: 1 addition & 83 deletions tests/models/test_omnivore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
import torch
import torchmultimodal.models.omnivore as omnivore
from tests.test_utils import assert_expected, set_rng_seed
from tests.test_utils import set_rng_seed
from torchmultimodal.utils.common import get_current_device


Expand All @@ -22,88 +22,6 @@ def omnivore_swin_t_model(device):
return omnivore.omnivore_swin_t().to(device)


@pytest.fixture()
def omnivore_swin_s_model(device):
return omnivore.omnivore_swin_s().to(device)


@pytest.fixture()
def omnivore_swin_b_model(device):
return omnivore.omnivore_swin_b().to(device)


def test_omnivore_swin_t_forward(omnivore_swin_t_model, device):
model = omnivore_swin_t_model

image = torch.randn((1, 3, 1, 112, 112), device=device) # B C D H W
image_score = model(image, input_type="image")

assert_expected(image_score.size(), torch.Size((1, 1000)))
assert_expected(
image_score.abs().sum(), torch.tensor(184.01417), rtol=1e-3, atol=1e-3
)

rgbd = torch.randn((1, 4, 1, 112, 112), device=device)
rgbd_score = model(rgbd, input_type="rgbd")
assert_expected(rgbd_score.size(), torch.Size((1, 19)))
assert_expected(rgbd_score.abs().sum(), torch.tensor(3.60813), rtol=1e-3, atol=1e-3)

video = torch.randn((1, 3, 4, 112, 112), device=device)
video_score = model(video, input_type="video")
assert_expected(video_score.size(), torch.Size((1, 400)))
assert_expected(
video_score.abs().sum(), torch.tensor(110.70048), rtol=1e-3, atol=1e-3
)


def test_omnivore_swin_s_forward(omnivore_swin_s_model, device):
model = omnivore_swin_s_model

image = torch.randn((1, 3, 1, 112, 112), device=device) # B C D H W
image_score = model(image, input_type="image")

assert_expected(image_score.size(), torch.Size((1, 1000)))
assert_expected(
image_score.abs().sum(), torch.tensor(239.73104), rtol=1e-3, atol=1e-3
)

rgbd = torch.randn((1, 4, 1, 112, 112), device=device)
rgbd_score = model(rgbd, input_type="rgbd")
assert_expected(rgbd_score.size(), torch.Size((1, 19)))
assert_expected(rgbd_score.abs().sum(), torch.tensor(5.80919), rtol=1e-3, atol=1e-3)

video = torch.randn((1, 3, 4, 112, 112), device=device)
video_score = model(video, input_type="video")
assert_expected(video_score.size(), torch.Size((1, 400)))
assert_expected(
video_score.abs().sum(), torch.tensor(136.49894), rtol=1e-3, atol=1e-3
)


def test_omnivore_swin_b_forward(omnivore_swin_b_model, device):
model = omnivore_swin_b_model

image = torch.randn((1, 3, 1, 112, 112), device=device) # B C D H W
image_score = model(image, input_type="image")

assert_expected(image_score.size(), torch.Size((1, 1000)))
assert_expected(
image_score.abs().sum(), torch.tensor(278.06488), rtol=1e-3, atol=1e-3
)

rgbd = torch.randn((1, 4, 1, 112, 112), device=device)
rgbd_score = model(rgbd, input_type="rgbd")
assert_expected(rgbd_score.size(), torch.Size((1, 19)))
assert_expected(rgbd_score.abs().sum(), torch.tensor(4.52186), rtol=1e-3, atol=1e-3)

video = torch.randn((1, 3, 4, 112, 112), device=device)
video_score = model(video, input_type="video")
assert_expected(video_score.size(), torch.Size((1, 400)))
assert_expected(
video_score.abs().sum(), torch.tensor(138.22859), rtol=1e-3, atol=1e-3
)


def test_omnivore_forward_wrong_input_type(omnivore_swin_t_model, device):
model = omnivore_swin_t_model

Expand Down
Loading