mirror of
https://github.com/open-mmlab/mmselfsup.git
synced 2025-06-03 14:59:38 +08:00
* [Feature]: Add milan ft config * [Feature]: Add milan linear prob * [Feature]: Set diff rank seed in mae ft * [Feature]: V1 * [Feature]: Add target generator * [Feature]: Add MILAN head and loss * [Feature]: Refine milan * [Feature]: Delete redundant mask and ids_shuffle * [Feature]: Delete redundant return value of attention masking * [Feature]: Detele return attention param * [Feature]: Add typehint and docstring for PromptDecoder and PromptAttention * [Feature]: Add type hint and docstring * [Feature]: Fix lint * [Fix]: Remove petrel backend * [Feature]: Delete redundant code in clip * [Feature]: Add ut for milan algorithm * [Feature]: Delete redundant code * [Feature]: Use mock for target generator * [Feature]: Add docstring * [Feature]: Create classification folder in milan * [Feature]: Add README * [Feature]: Add metafile * [Feature]: Add main paper readme * [Feature]: Update model zoom * [Feature]: Fix review * [Feature]: Fix config path bug * [Feature]: Fix review#2 * [Feature]: Delete MILAN loss * [Fix]: Add metafile * [Fix]: Fix lint * [Feature]: Change the test milan * [Feature]: Update the config file name
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
# Copyright (c) OpenMMLab. All rights reserved.
|
|
import copy
|
|
import platform
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
import torch
|
|
|
|
from mmselfsup.models.algorithms import MILAN
|
|
from mmselfsup.structures import SelfSupDataSample
|
|
from mmselfsup.utils import register_all_modules
|
|
|
|
register_all_modules()
|
|
|
|
backbone = dict(type='MILANViT', arch='b', patch_size=16, mask_ratio=0.75)
|
|
neck = dict(
|
|
type='MILANPretrainDecoder',
|
|
patch_size=16,
|
|
in_chans=3,
|
|
embed_dim=768,
|
|
decoder_embed_dim=512,
|
|
decoder_depth=8,
|
|
decoder_num_heads=16,
|
|
mlp_ratio=4.,
|
|
)
|
|
loss = dict(type='CosineSimilarityLoss', shift_factor=2.0, scale_factor=2.0)
|
|
head = dict(type='MILANPretrainHead', loss=loss)
|
|
|
|
|
|
@pytest.mark.skipif(platform.system() == 'Windows', reason='Windows mem limit')
|
|
def test_milan():
|
|
data_preprocessor = {
|
|
'mean': [0.5, 0.5, 0.5],
|
|
'std': [0.5, 0.5, 0.5],
|
|
'bgr_to_rgb': True
|
|
}
|
|
|
|
alg = MILAN(
|
|
backbone=backbone,
|
|
neck=neck,
|
|
head=head,
|
|
data_preprocessor=copy.deepcopy(data_preprocessor))
|
|
|
|
target_generator = MagicMock(
|
|
return_value=(torch.ones(2, 197, 512), torch.ones(2, 197, 197)))
|
|
alg.target_generator = target_generator
|
|
|
|
fake_data = {
|
|
'inputs': [torch.randn((2, 3, 224, 224))],
|
|
'data_sample': [SelfSupDataSample() for _ in range(2)]
|
|
}
|
|
fake_batch_inputs, fake_data_samples = alg.data_preprocessor(fake_data)
|
|
fake_outputs = alg(fake_batch_inputs, fake_data_samples, mode='loss')
|
|
assert isinstance(fake_outputs['loss'].item(), float)
|