-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2417c01
commit 6903af4
Showing
9 changed files
with
250 additions
and
2 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,4 @@ | ||
"""Test for otx.algorithms.common.adapters.mmcv.ops""" | ||
# Copyright (C) 2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# |
20 changes: 20 additions & 0 deletions
20
tests/unit/algorithms/common/adapters/mmcv/ops/test_multi_scale_deformable_attn_pytorch.py
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,20 @@ | ||
"""Test for otx.algorithms.common.adapters.mmcv.ops.multi_scale_deformable_attn_pytorch.""" | ||
# Copyright (C) 2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
import torch | ||
|
||
from otx.algorithms.common.adapters.mmcv.ops import multi_scale_deformable_attn_pytorch | ||
from tests.test_suite.e2e_test_system import e2e_pytest_unit | ||
|
||
|
||
@e2e_pytest_unit | ||
def test_multi_scale_deformable_attn_pytorch(): | ||
value = torch.randn([1, 22223, 8, 32]) | ||
value_spatial_shapes = torch.tensor([[100, 167], [50, 84], [25, 42], [13, 21]]) | ||
sampling_locations = torch.randn([1, 2223, 8, 4, 4, 2]) | ||
attention_weights = torch.randn([1, 2223, 8, 4, 4]) | ||
|
||
out = multi_scale_deformable_attn_pytorch(value, value_spatial_shapes, sampling_locations, attention_weights) | ||
assert out.shape == torch.Size([1, 2223, 256]) |
4 changes: 4 additions & 0 deletions
4
tests/unit/algorithms/common/adapters/mmdeploy/ops/__init__.py
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,4 @@ | ||
"""Test for otx.algorithms.common.adapters.mmdeploy.ops""" | ||
# Copyright (C) 2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# |
18 changes: 18 additions & 0 deletions
18
tests/unit/algorithms/common/adapters/mmdeploy/ops/test_custom_ops.py
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,18 @@ | ||
"""Test for otx.algorithms.common.adapters.mmdeploy.ops.custom_ops.""" | ||
# Copyright (C) 2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
from mmdeploy.core import SYMBOLIC_REWRITER | ||
|
||
from otx.algorithms.common.adapters.mmdeploy.ops.custom_ops import ( | ||
squeeze__default, | ||
grid_sampler__default, | ||
) | ||
from tests.test_suite.e2e_test_system import e2e_pytest_unit | ||
|
||
|
||
@e2e_pytest_unit | ||
def test_symbolic_registery(): | ||
assert len(SYMBOLIC_REWRITER._registry._rewrite_records["squeeze"]) == 1 | ||
assert len(SYMBOLIC_REWRITER._registry._rewrite_records["grid_sampler"]) == 1 |
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
19 changes: 19 additions & 0 deletions
19
...orithms/detection/adapters/mmdet/models/detectors/test_custom_deformable_detr_detector.py
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,19 @@ | ||
"""Test for CustomDeformableDETRHead.""" | ||
# Copyright (C) 2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
from mmdet.models.builder import build_detector | ||
|
||
from otx.algorithms.detection.adapters.mmdet.models.detectors.custom_deformable_detr_detector import ( | ||
CustomDeformableDETR, | ||
) | ||
from tests.test_suite.e2e_test_system import e2e_pytest_unit | ||
|
||
|
||
class TestCustomDeformableDETR: | ||
@e2e_pytest_unit | ||
def test_custom_deformable_detr_build(self, fxt_cfg_custom_deformable_detr): | ||
model = build_detector(fxt_cfg_custom_deformable_detr) | ||
assert isinstance(model, CustomDeformableDETR) | ||
assert model.task_adapt is not None |
4 changes: 4 additions & 0 deletions
4
tests/unit/algorithms/detection/adapters/mmdet/models/heads/__init__.py
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,4 @@ | ||
"""Test for otx.algorithms.mmdetection.adapters.mmdet.models.heads.""" | ||
# Copyright (C) 2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# |
96 changes: 96 additions & 0 deletions
96
...unit/algorithms/detection/adapters/mmdet/models/heads/test_custom_deformable_detr_head.py
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,96 @@ | ||
"""Test for otx.algorithms.mmdetection.adapters.mmdet.models.heads.custom_deformable_detr_head.""" | ||
# Copyright (C) 2023 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
import numpy as np | ||
import torch | ||
import pytest | ||
|
||
from mmcv.utils import ConfigDict | ||
from mmdet.models.builder import build_detector | ||
from mmdet.models.dense_heads.deformable_detr_head import DeformableDETRHead | ||
|
||
from tests.test_suite.e2e_test_system import e2e_pytest_unit | ||
|
||
|
||
class TestCustomDeformableDETRHead: | ||
@pytest.fixture(autouse=True) | ||
def setup(self) -> None: | ||
cfg = ConfigDict( | ||
type="CustomDeformableDETRHead", | ||
num_query=300, | ||
num_classes=80, | ||
in_channels=2048, | ||
sync_cls_avg_factor=True, | ||
with_box_refine=True, | ||
as_two_stage=True, | ||
transformer=dict( | ||
type="DeformableDetrTransformer", | ||
encoder=dict( | ||
type="DetrTransformerEncoder", | ||
num_layers=6, | ||
transformerlayers=dict( | ||
type="BaseTransformerLayer", | ||
attn_cfgs=dict(type="MultiScaleDeformableAttention", embed_dims=256), | ||
feedforward_channels=1024, | ||
ffn_dropout=0.1, | ||
operation_order=("self_attn", "norm", "ffn", "norm"), | ||
), | ||
), | ||
decoder=dict( | ||
type="DeformableDetrTransformerDecoder", | ||
num_layers=6, | ||
return_intermediate=True, | ||
transformerlayers=dict( | ||
type="DetrTransformerDecoderLayer", | ||
attn_cfgs=[ | ||
dict(type="MultiheadAttention", embed_dims=256, num_heads=8, dropout=0.1), | ||
dict(type="MultiScaleDeformableAttention", embed_dims=256), | ||
], | ||
feedforward_channels=1024, | ||
ffn_dropout=0.1, | ||
operation_order=("self_attn", "norm", "cross_attn", "norm", "ffn", "norm"), | ||
), | ||
), | ||
), | ||
positional_encoding=dict(type="SinePositionalEncoding", num_feats=128, normalize=True, offset=-0.5), | ||
loss_cls=dict(type="FocalLoss", use_sigmoid=True, gamma=2.0, alpha=0.25, loss_weight=2.0), | ||
loss_bbox=dict(type="L1Loss", loss_weight=5.0), | ||
loss_iou=dict(type="GIoULoss", loss_weight=2.0), | ||
) | ||
self.head = build_detector(cfg) | ||
|
||
@e2e_pytest_unit | ||
def test_forward(self, mocker): | ||
def return_second_arg(a, b): | ||
return b | ||
|
||
mocker.patch.object(DeformableDETRHead, "forward", side_effect=return_second_arg) | ||
|
||
feats = ( | ||
torch.randn([1, 256, 100, 167]), | ||
torch.randn([1, 256, 50, 84]), | ||
torch.randn([1, 256, 25, 42]), | ||
torch.randn([1, 256, 13, 21]), | ||
) | ||
img_metas = [ | ||
{ | ||
"filename": None, | ||
"ori_filename": None, | ||
"ori_shape": (128, 128, 3), | ||
"img_shape": torch.Tensor([800, 1333]), | ||
"pad_shape": (800, 1333, 3), | ||
"scale_factor": np.array([10.4140625, 6.25, 10.4140625, 6.25], dtype=np.float32), | ||
"flip": False, | ||
"flip_direction": None, | ||
"img_norm_cfg": { | ||
"mean": np.array([123.675, 116.28, 103.53], dtype=np.float32), | ||
"std": np.array([58.395, 57.12, 57.375], dtype=np.float32), | ||
"to_rgb": False, | ||
}, | ||
} | ||
] | ||
out = self.head(feats, img_metas) | ||
assert out[0].get("batch_input_shape") == (800, 1333) | ||
assert out[0].get("img_shape") == (800, 1333, 3) |