-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move image masking transform to core (#71)
Summary: Pull Request resolved: #71 Move image masking transform to core without any logical changes. Add unit test and typing info Test plan pytest Sanity checks python -m flava.finetune config=flava/configs/finetuning/qnli.yaml training.lightning.accelerator=cpu training.lightning.gpus=0 training.lightning.strategy=null python -m flava.train config=flava/configs/pretraining/debug.yaml training.lightning.accelerator=cpu training.lightning.gpus=0 training.lightning.strategy=null Test Plan: Imported from OSS Reviewed By: ebsmothers Differential Revision: D39049377 Pulled By: ankitade fbshipit-source-id: a47207b11921cb3374a8d87107e39e8ab7239484
- Loading branch information
1 parent
a34c2d0
commit ae7d698
Showing
3 changed files
with
369 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import pytest | ||
import torch | ||
from tests.test_utils import assert_expected, set_rng_seed | ||
from torchmultimodal.transforms.flava_transform import FLAVAImageTransform | ||
from torchvision import transforms | ||
|
||
|
||
class TestFLAVAImageTransform: | ||
@pytest.fixture(autouse=True) | ||
def set_seed(self): | ||
set_rng_seed(1234) | ||
|
||
def test_image_transform_train(self): | ||
transform = FLAVAImageTransform( | ||
encoder_input_size=3, | ||
codebook_input_size=3, | ||
mask_max_patches=1, | ||
mask_min_patches=1, | ||
mask_num_patches=1, | ||
) | ||
input = transforms.ToPILImage()(torch.ones(2, 2)) | ||
out = transform(input) | ||
expected_image = torch.Tensor( | ||
[ | ||
[ | ||
[1.9303, 1.9303, 1.9303], | ||
[1.9303, 1.9303, 1.9303], | ||
[1.9303, 1.9303, 1.9303], | ||
], | ||
[ | ||
[2.0749, 2.0749, 2.0749], | ||
[2.0749, 2.0749, 2.0749], | ||
[2.0749, 2.0749, 2.0749], | ||
], | ||
[ | ||
[2.1459, 2.1459, 2.1459], | ||
[2.1459, 2.1459, 2.1459], | ||
[2.1459, 2.1459, 2.1459], | ||
], | ||
] | ||
) | ||
|
||
assert_expected(out["image"], expected_image, atol=1e-4, rtol=1e-4) | ||
assert_expected(out["image_for_codebook"], torch.full((3, 3, 3), 0.9)) | ||
assert out["image_patches_mask"].sum() == 1 |
Oops, something went wrong.