Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Self-SL configs for SegNext #2215

Merged
merged 11 commits into from
Sep 19, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- Add Semi-SL Mean Teacher algorithm for Instance Segmentation task(<https://github.com/openvinotoolkit/training_extensions/pull/2444>)
- Official supports for YOLOX-X, YOLOX-L, YOLOX-S, ResNeXt101-ATSS (<https://github.com/openvinotoolkit/training_extensions/pull/2485>)
- Add new argument to track resource usage in train command(<https://github.com/openvinotoolkit/training_extensions/pull/2500>)
- Add Self-SL for semantic segmentation of SegNext families (<https://github.com/openvinotoolkit/training_extensions/pull/2215>)

### Enhancements

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Initialization of OCR-Lite-HRnet-18-mod2 model for Self-SL Segmentation Task."""

# Copyright (C) 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
goodsong81 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Data Pipeline of SegNext model for Segmentation Task."""

# Copyright (C) 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
goodsong81 marked this conversation as resolved.
Show resolved Hide resolved

# pylint: disable=invalid-name
_base_ = ["../../base/data/selfsl/data_pipeline.py"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Hyperparameters.
hyper_parameters:
parameter_overrides:
learning_parameters:
batch_size:
default_value: 32
learning_rate:
default_value: 0.0001
learning_rate_warmup_iters:
default_value: 0
num_iters:
default_value: 10
sungchul2 marked this conversation as resolved.
Show resolved Hide resolved
enable_early_stopping:
default_value: false
algo_backend:
train_type:
default_value: Selfsupervised
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Model configuration of SegNext-B model for Self-SL Segmentation Task."""

# Copyright (C) 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
goodsong81 marked this conversation as resolved.
Show resolved Hide resolved

# pylint: disable=invalid-name

_base_ = [
"../../../../../recipes/stages/segmentation/selfsl.py",
"../../../../common/adapters/mmcv/configs/backbones/segnext.py",
]


model = dict(
type="DetConB",
pretrained="https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/segnext/mscan_b_20230227-3ab7d230.pth",
num_classes=256,
num_samples=16,
downsample=8,
input_transform="resize_concat",
in_index=[1, 2, 3],
backbone=dict(
embed_dims=[64, 128, 320, 512],
depths=[3, 3, 12, 3],
drop_path_rate=0.1,
norm_cfg=dict(type="BN", requires_grad=True),
),
neck=dict(
type="SelfSLMLP",
in_channels=960,
hid_channels=1920,
out_channels=256,
norm_cfg=dict(type="BN1d", requires_grad=True),
with_avg_pool=False,
),
head=dict(
type="DetConHead",
predictor=dict(
type="SelfSLMLP",
in_channels=256,
hid_channels=1920,
out_channels=256,
norm_cfg=dict(type="BN1d", requires_grad=True),
with_avg_pool=False,
),
loss_cfg=dict(type="DetConLoss", temperature=0.1),
),
)

optimizer = dict(paramwise_cfg=dict(custom_keys={"pos_block": dict(decay_mult=0.0), "norm": dict(decay_mult=0.0)}))
load_from = None
resume_from = None
fp16 = None
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Initialization of OCR-Lite-HRnet-18-mod2 model for Self-SL Segmentation Task."""

# Copyright (C) 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
goodsong81 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Data Pipeline of HR-Net model for Segmentation Task."""

# Copyright (C) 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
goodsong81 marked this conversation as resolved.
Show resolved Hide resolved

# pylint: disable=invalid-name
_base_ = ["../../base/data/selfsl/data_pipeline.py"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Hyperparameters.
hyper_parameters:
parameter_overrides:
learning_parameters:
batch_size:
default_value: 32
learning_rate:
default_value: 0.0001
learning_rate_warmup_iters:
default_value: 0
num_iters:
default_value: 10
enable_early_stopping:
default_value: false
algo_backend:
train_type:
default_value: Selfsupervised
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Model configuration of SegNext-S model for Self-SL Segmentation Task."""

# Copyright (C) 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
goodsong81 marked this conversation as resolved.
Show resolved Hide resolved

# pylint: disable=invalid-name

_base_ = [
"../../../../../recipes/stages/segmentation/selfsl.py",
"../../../../common/adapters/mmcv/configs/backbones/segnext.py",
]


model = dict(
type="DetConB",
pretrained="https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/segnext/mscan_s_20230227-f33ccdf2.pth",
num_classes=256,
num_samples=16,
downsample=8,
input_transform="resize_concat",
in_index=[1, 2, 3],
backbone=dict(
embed_dims=[64, 128, 320, 512],
depths=[2, 2, 4, 2],
norm_cfg=dict(type="BN", requires_grad=True),
),
neck=dict(
type="SelfSLMLP",
in_channels=960,
hid_channels=1920,
out_channels=256,
norm_cfg=dict(type="BN1d", requires_grad=True),
with_avg_pool=False,
),
head=dict(
type="DetConHead",
predictor=dict(
type="SelfSLMLP",
in_channels=256,
hid_channels=1920,
out_channels=256,
norm_cfg=dict(type="BN1d", requires_grad=True),
with_avg_pool=False,
),
loss_cfg=dict(type="DetConLoss", temperature=0.1),
),
)

optimizer = dict(paramwise_cfg=dict(custom_keys={"pos_block": dict(decay_mult=0.0), "norm": dict(decay_mult=0.0)}))
load_from = None
resume_from = None
fp16 = None
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Initialization of OCR-Lite-HRnet-18-mod2 model for Self-SL Segmentation Task."""

# Copyright (C) 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
goodsong81 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Data Pipeline of HR-Net model for Segmentation Task."""

# Copyright (C) 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
goodsong81 marked this conversation as resolved.
Show resolved Hide resolved

# pylint: disable=invalid-name
_base_ = ["../../base/data/selfsl/data_pipeline.py"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Hyperparameters.
hyper_parameters:
parameter_overrides:
learning_parameters:
batch_size:
default_value: 32
learning_rate:
default_value: 0.0001
learning_rate_warmup_iters:
default_value: 0
num_iters:
default_value: 10
enable_early_stopping:
default_value: false
algo_backend:
train_type:
default_value: Selfsupervised
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Model configuration of SegNext-T model for Self-SL Segmentation Task."""

# Copyright (C) 2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions
# and limitations under the License.
goodsong81 marked this conversation as resolved.
Show resolved Hide resolved

# pylint: disable=invalid-name

_base_ = [
"../../../../../recipes/stages/segmentation/selfsl.py",
"../../../../common/adapters/mmcv/configs/backbones/segnext.py",
]


model = dict(
type="DetConB",
pretrained="https://download.openmmlab.com/mmsegmentation/v0.5/pretrain/segnext/mscan_t_20230227-119e8c9f.pth",
num_classes=256,
num_samples=16,
downsample=8,
input_transform="resize_concat",
in_index=[1, 2, 3],
neck=dict(
type="SelfSLMLP",
in_channels=480,
hid_channels=960,
out_channels=256,
norm_cfg=dict(type="BN1d", requires_grad=True),
with_avg_pool=False,
),
head=dict(
type="DetConHead",
predictor=dict(
type="SelfSLMLP",
in_channels=256,
hid_channels=960,
out_channels=256,
norm_cfg=dict(type="BN1d", requires_grad=True),
with_avg_pool=False,
),
loss_cfg=dict(type="DetConLoss", temperature=0.1),
),
)

optimizer = dict(paramwise_cfg=dict(custom_keys={"pos_block": dict(decay_mult=0.0), "norm": dict(decay_mult=0.0)}))
load_from = None
resume_from = None
fp16 = None
6 changes: 0 additions & 6 deletions tests/e2e/cli/semantic_segmentation/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ class TestToolsOTXSelfSLSegmentation:
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_train(self, template, tmp_dir_path):
tmp_dir_path_1 = tmp_dir_path / "segmentation/test_selfsl"
if not (Path(template.model_template_path).parent / "selfsl").is_dir():
pytest.skip("Self-SL training type isn't available for this template")
otx_train_testing(template, tmp_dir_path_1, otx_dir, args_selfsl)
template_work_dir = get_template_dir(template, tmp_dir_path_1)
assert (Path(template_work_dir) / "selfsl").is_dir()
Expand All @@ -332,8 +330,6 @@ def test_otx_train(self, template, tmp_dir_path):
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_eval(self, template, tmp_dir_path):
if not (Path(template.model_template_path).parent / "selfsl").is_dir():
pytest.skip("Self-SL training type isn't available for this template")
tmp_dir_path = tmp_dir_path / "segmentation/test_selfsl_sl"
otx_eval_testing(template, tmp_dir_path, otx_dir, args)

Expand All @@ -342,8 +338,6 @@ def test_otx_eval(self, template, tmp_dir_path):
@pytest.mark.skipif(MULTI_GPU_UNAVAILABLE, reason="The number of gpu is insufficient")
@pytest.mark.parametrize("template", templates, ids=templates_ids)
def test_otx_multi_gpu_train_selfsl(self, template, tmp_dir_path):
if not (Path(template.model_template_path).parent / "selfsl").is_dir():
pytest.skip("Self-SL training type isn't available for this template")
tmp_dir_path = tmp_dir_path / "segmentation/test_multi_gpu_selfsl"
args_selfsl_multigpu = copy.deepcopy(args_selfsl)
args_selfsl_multigpu["--gpus"] = "0,1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,13 @@ def test_otx_multi_gpu_train_semisl(self, template, tmp_dir_path):
@e2e_pytest_component
@pytest.mark.parametrize("template", default_templates, ids=default_templates_ids)
def test_otx_train_selfsl(self, template, tmp_dir_path):
if not (Path(template.model_template_path).parent / "selfsl").is_dir():
pytest.skip("Self-SL training type isn't available for this template")
tmp_dir_path = tmp_dir_path / "segmentation/test_selfsl"
otx_train_testing(template, tmp_dir_path, otx_dir, args_selfsl)

@e2e_pytest_component
@pytest.mark.skipif(MULTI_GPU_UNAVAILABLE, reason="The number of gpu is insufficient")
@pytest.mark.parametrize("template", default_templates, ids=default_templates_ids)
def test_otx_multi_gpu_train_selfsl(self, template, tmp_dir_path):
if not (Path(template.model_template_path).parent / "selfsl").is_dir():
pytest.skip("Self-SL training type isn't available for this template")
tmp_dir_path = tmp_dir_path / "segmentation/test_multi_gpu_selfsl"
args_selfsl_multigpu = copy.deepcopy(args_selfsl)
args_selfsl_multigpu["--gpus"] = "0,1"
Expand Down
Loading