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

Move semantic-segmentation related codes to otx adapters #1911

Merged
merged 22 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions docs/source/guide/reference/mpa/modules/models/backbones.rst

This file was deleted.

21 changes: 0 additions & 21 deletions docs/source/guide/reference/mpa/modules/models/heads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@ Heads
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.heads.aggregator_mixin
:members:
:undoc-members:


.. automodule:: otx.mpa.modules.models.heads.custom_cls_head
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.heads.custom_fcn_head
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.heads.custom_hierarchical_linear_cls_head
:members:
:undoc-members:
Expand All @@ -38,22 +29,10 @@ Heads
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.heads.mix_loss_mixin
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.heads.non_linear_cls_head
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.heads.pixel_weights_mixin
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.heads.segment_out_norm_mixin
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.heads.semisl_cls_head
:members:
:undoc-members:
Expand Down
3 changes: 0 additions & 3 deletions docs/source/guide/reference/mpa/modules/models/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ Models
.. toctree::
:maxdepth: 1

backbones
classifiers
heads
losses
scalar_schedulers
segmentors
utils
17 changes: 0 additions & 17 deletions docs/source/guide/reference/mpa/modules/models/losses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ Losses
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.losses.base_pixel_loss
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.losses.base_weighted_loss
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.losses.cross_entropy_loss_with_ignore
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.losses.cross_entropy_loss
:members:
:undoc-members:
Expand All @@ -41,11 +29,6 @@ Losses
:members:
:undoc-members:


.. automodule:: otx.mpa.modules.models.losses.mpa_pixel_base
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.models.losses.utils
:members:
:undoc-members:

This file was deleted.

30 changes: 0 additions & 30 deletions docs/source/guide/reference/mpa/modules/models/segmentors.rst

This file was deleted.

4 changes: 0 additions & 4 deletions docs/source/guide/reference/mpa/modules/ov/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ Models
.. automodule:: otx.mpa.modules.ov.models.mmcls
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.ov.models.mmseg
:members:
:undoc-members:
4 changes: 0 additions & 4 deletions docs/source/guide/reference/mpa/modules/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ Utils
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.utils.seg_utils
:members:
:undoc-members:

.. automodule:: otx.mpa.modules.utils.task_adapt
:members:
:undoc-members:
14 changes: 13 additions & 1 deletion otx/algorithms/segmentation/adapters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
"""Adapters for Segmentation."""


# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
# 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.
54 changes: 49 additions & 5 deletions otx/algorithms/segmentation/adapters/mmseg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
"""OTX Adapters - mmseg."""

# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from .data import MPASegDataset
from .models import DetConB, DetConLoss, SelfSLMLP, SupConDetConB
# 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.


from .datasets import MPASegDataset
from .models import (
ClassIncrEncoderDecoder,
ConstantScalarScheduler,
CrossEntropyLossWithIgnore,
CustomFCNHead,
DetConB,
DetConLoss,
LiteHRNet,
MeanTeacherSegmentor,
MMOVBackbone,
MMOVDecodeHead,
PolyScalarScheduler,
SelfSLMLP,
StepScalarScheduler,
SupConDetConB,
)

# fmt: off
# isort: off
Expand All @@ -16,4 +44,20 @@
# fmt: off
# isort: on

__all__ = ["MPASegDataset", "DetConLoss", "SelfSLMLP", "DetConB", "SupConDetConB"]
__all__ = [
"MPASegDataset",
"LiteHRNet",
"MMOVBackbone",
"CustomFCNHead",
"MMOVDecodeHead",
"DetConLoss",
"SelfSLMLP",
"ConstantScalarScheduler",
"PolyScalarScheduler",
"StepScalarScheduler",
"DetConB",
"CrossEntropyLossWithIgnore",
"SupConDetConB",
"ClassIncrEncoderDecoder",
"MeanTeacherSegmentor",
]
eunwoosh marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""OTX Algorithms - Segmentation Dataset."""

# Copyright (C) 2022 Intel Corporation
# 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.
Expand All @@ -18,13 +18,17 @@
from .pipelines import (
LoadAnnotationFromOTXDataset,
LoadImageFromOTXDataset,
MaskCompose,
ProbCompose,
TwoCropTransform,
)

__all__ = [
"get_annotation_mmseg_format",
"LoadImageFromOTXDataset",
"LoadAnnotationFromOTXDataset",
"MPASegDataset",
"LoadImageFromOTXDataset",
"MaskCompose",
"ProbCompose",
"TwoCropTransform",
"get_annotation_mmseg_format",
"MPASegDataset",
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Base MMDataset for Segmentation Task."""

# Copyright (C) 2022 Intel Corporation
# 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""OTX Algorithms - Segmentation pipelines."""

# 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.

from .compose import MaskCompose, ProbCompose
from .loads import LoadAnnotationFromOTXDataset, LoadImageFromOTXDataset
from .transforms import TwoCropTransform

__all__ = ["MaskCompose", "ProbCompose", "LoadImageFromOTXDataset", "LoadAnnotationFromOTXDataset", "TwoCropTransform"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Copyright (C) 2022 Intel Corporation
"""Collection of compose pipelines for segmentation task."""

# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

Expand All @@ -11,8 +13,11 @@
from scipy.ndimage import gaussian_filter


# pylint: disable=consider-using-f-string
harimkang marked this conversation as resolved.
Show resolved Hide resolved
@PIPELINES.register_module()
class ProbCompose(object):
class ProbCompose:
"""Compose pipelines in a list and enable or disable them with the probability."""

def __init__(self, transforms, probs):
assert isinstance(transforms, Sequence)
assert isinstance(probs, Sequence)
Expand All @@ -35,6 +40,7 @@ def __init__(self, transforms, probs):
raise TypeError(f"transform must be callable or a dict, but got {type(transform)}")

def __call__(self, data):
"""Callback function of ProbCompose."""
rand_value = np.random.rand()
transform_id = np.max(np.where(rand_value > self.limits)[0])

Expand All @@ -44,17 +50,20 @@ def __call__(self, data):
return data

def __repr__(self):
"""Repr."""
format_string = self.__class__.__name__ + "("
for t in self.transforms:
format_string += "\n"
format_string += " {0}".format(t)
format_string += f" {t}"
format_string += "\n)"

return format_string


@PIPELINES.register_module()
class MaskCompose(object):
class MaskCompose:
"""Compose mask-related pipelines in a list and enable or disable them with the probability."""

def __init__(self, transforms, prob, lambda_limits=(4, 16), keep_original=False):
self.keep_original = keep_original
self.prob = prob
Expand Down Expand Up @@ -102,6 +111,7 @@ def _mix_img(main_img, aux_img, mask):
return np.where(np.expand_dims(mask, axis=2), main_img, aux_img)

def __call__(self, data):
"""Callback function of MaskCompose."""
main_data = self._apply_transforms(deepcopy(data), self.transforms)
assert main_data is not None
if not self.keep_original and np.random.rand() > self.prob:
Expand All @@ -123,10 +133,11 @@ def __call__(self, data):
return main_data

def __repr__(self):
"""Repr."""
format_string = self.__class__.__name__ + "("
for t in self.transforms:
format_string += "\n"
format_string += " {0}".format(t)
format_string += f" {t}"
format_string += "\n)"

return format_string
Loading