Skip to content

Commit

Permalink
Add intg test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaegukhyun committed Jun 16, 2023
1 parent 6903af4 commit d54540b
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
from mmdet.models.builder import DETECTORS
from mmdet.models.detectors.deformable_detr import DeformableDETR

from otx.algorithms.common.adapters.mmcv.hooks.recording_forward_hook import (
ActivationMapHook,
FeatureVectorHook,
)
from otx.algorithms.common.adapters.mmdeploy.utils import is_mmdeploy_enabled


@DETECTORS.register_module()
class CustomDeformableDETR(DeformableDETR):
Expand All @@ -18,3 +24,28 @@ class CustomDeformableDETR(DeformableDETR):
def __init__(self, *args, task_adapt=None, **kwargs):
super().__init__(*args, **kwargs)
self.task_adapt = task_adapt


if is_mmdeploy_enabled():
from mmdeploy.core import FUNCTION_REWRITER

@FUNCTION_REWRITER.register_rewriter(
"otx.algorithms.detection.adapters.mmdet.models.detectors.custom_deformable_detr_detector.CustomDeformableDETR.simple_test"
)
def custom_deformable_detr__simple_test(ctx, self, img, img_metas, **kwargs):
"""Function for custom_mask_rcnn__simple_test."""
height = int(img_metas[0]["img_shape"][0])
width = int(img_metas[0]["img_shape"][1])
img_metas[0]["batch_input_shape"] = (height, width)
img_metas[0]["img_shape"] = (height, width, 3)
feat = self.extract_feat(img)
outs = self.bbox_head(feat, img_metas)
bbox_results = self.bbox_head.get_bboxes(*outs, img_metas=img_metas, **kwargs)

if ctx.cfg["dump_features"]:
feature_vector = FeatureVectorHook.func(feat)
cls_scores = outs[0]
saliency_map = ActivationMapHook.func(cls_scores)
return (*bbox_results, feature_vector, saliency_map)

return bbox_results
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from .cross_dataset_detector_head import CrossDatasetDetectorHead
from .custom_anchor_generator import SSDAnchorGeneratorClustered
from .custom_atss_head import CustomATSSHead, CustomATSSHeadTrackingLossDynamics
from .custom_deformable_detr_head import CustomDeformableDETRHead
from .custom_retina_head import CustomRetinaHead
from .custom_roi_head import CustomRoIHead
from .custom_ssd_head import CustomSSDHead
Expand All @@ -17,7 +16,6 @@
"CrossDatasetDetectorHead",
"SSDAnchorGeneratorClustered",
"CustomATSSHead",
"CustomDeformableDETRHead",
"CustomRetinaHead",
"CustomSSDHead",
"CustomRoIHead",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
num_outs=4,
),
bbox_head=dict(
type="CustomDeformableDETRHead",
type="DeformableDETRHead",
num_query=300,
num_classes=80,
in_channels=2048,
Expand Down
42 changes: 24 additions & 18 deletions tests/e2e/cli/detection/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,16 @@
templates = Registry("otx/algorithms/detection").filter(task_type="DETECTION").templates
templates_ids = [template.model_template_id for template in templates]

template_experimental = parse_model_template(
"otx/algorithms/detection/configs/detection/resnet50_deformable-detr/template_experimental.yaml"
)
templates_w_experimental = templates + [template_experimental]
templates_ids_w_experimental = templates_ids + [template_experimental.model_template_id]


class TestToolsMPADetection:
@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_train(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_train_testing(template, tmp_dir_path, otx_dir, args0)
Expand All @@ -104,7 +110,7 @@ def test_otx_train(self, template, tmp_dir_path):

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_resume(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_resume"
otx_resume_testing(template, tmp_dir_path, otx_dir, args)
Expand All @@ -118,29 +124,29 @@ def test_otx_resume(self, template, tmp_dir_path):

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
@pytest.mark.parametrize("dump_features", [True, False])
def test_otx_export(self, template, tmp_dir_path, dump_features):
tmp_dir_path = tmp_dir_path / "detection"
otx_export_testing(template, tmp_dir_path, dump_features)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_export_fp16(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_export_testing(template, tmp_dir_path, half_precision=True)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_eval(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_eval_testing(template, tmp_dir_path, otx_dir, args)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
@pytest.mark.parametrize("half_precision", [True, False])
def test_otx_eval_openvino(self, template, tmp_dir_path, half_precision):
tmp_dir_path = tmp_dir_path / "detection"
Expand Down Expand Up @@ -190,42 +196,42 @@ def test_otx_explain_process_saliency_maps_openvino(self, template, tmp_dir_path

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_demo(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_demo_testing(template, tmp_dir_path, otx_dir, args)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_demo_openvino(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_demo_openvino_testing(template, tmp_dir_path, otx_dir, args)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_deploy_openvino(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_deploy_openvino_testing(template, tmp_dir_path, otx_dir, args)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_eval_deployment(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_eval_deployment_testing(template, tmp_dir_path, otx_dir, args, threshold=0.0)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_demo_deployment(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_demo_deployment_testing(template, tmp_dir_path, otx_dir, args)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_hpo(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_hpo"
otx_hpo_testing(template, tmp_dir_path, otx_dir, args)
Expand Down Expand Up @@ -282,7 +288,7 @@ def test_nncf_eval_openvino(self, template, tmp_dir_path):

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_pot_optimize(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
pot_optimize_testing(template, tmp_dir_path, otx_dir, args)
Expand All @@ -296,15 +302,15 @@ def test_pot_validate_fq(self, template, tmp_dir_path):

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_pot_eval(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
pot_eval_testing(template, tmp_dir_path, otx_dir, args)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.skipif(MULTI_GPU_UNAVAILABLE, reason="The number of gpu is insufficient")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_multi_gpu_train(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_multi_gpu"
args1 = copy.deepcopy(args)
Expand All @@ -314,22 +320,22 @@ def test_otx_multi_gpu_train(self, template, tmp_dir_path):

class TestToolsMPASemiSLDetection:
@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_train(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_semisl"
otx_train_testing(template, tmp_dir_path, otx_dir, args_semisl)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_eval(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_semisl"
otx_eval_testing(template, tmp_dir_path, otx_dir, args)

@e2e_pytest_component
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.skipif(MULTI_GPU_UNAVAILABLE, reason="The number of gpu is insufficient")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_multi_gpu_train_semisl(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection/test_multi_gpu_semisl"
args_semisl_multigpu = copy.deepcopy(args_semisl)
Expand Down
18 changes: 13 additions & 5 deletions tests/integration/cli/detection/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,18 @@
templates = Registry("otx/algorithms/detection").filter(task_type="DETECTION").templates
templates_ids = [template.model_template_id for template in templates]

experimental_template = parse_model_template(
"otx/algorithms/detection/configs/detection/resnet50_deformable-detr/template_experimental.yaml"
)
experimental_template_id = experimental_template.model_template_id

templates_w_experimental = templates + [experimental_template]
templates_ids_w_experimental = templates_ids + [experimental_template_id]


class TestDetectionCLI:
@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_train(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_train_testing(template, tmp_dir_path, otx_dir, args)
Expand All @@ -90,26 +98,26 @@ def test_otx_resume(self, template, tmp_dir_path):
otx_resume_testing(template, tmp_dir_path, otx_dir, args1)

@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
@pytest.mark.parametrize("dump_features", [True, False])
def test_otx_export(self, template, tmp_dir_path, dump_features):
tmp_dir_path = tmp_dir_path / "detection"
otx_export_testing(template, tmp_dir_path, dump_features, check_ir_meta=True)

@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_export_fp16(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_export_testing(template, tmp_dir_path, half_precision=True)

@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_export_onnx(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_export_testing(template, tmp_dir_path, half_precision=False, is_onnx=True)

@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
def test_otx_eval(self, template, tmp_dir_path):
tmp_dir_path = tmp_dir_path / "detection"
otx_eval_testing(template, tmp_dir_path, otx_dir, args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def fxt_cfg_custom_deformable_detr(num_classes: int = 3):
num_outs=4,
),
bbox_head=dict(
type="CustomDeformableDETRHead",
type="DeformableDETRHead",
num_query=300,
num_classes=80,
in_channels=2048,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test for CustomDeformableDETRHead."""
"""Test for CustomDeformableDETR Detector."""
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
Expand Down

This file was deleted.

Loading

0 comments on commit d54540b

Please sign in to comment.