From eb11993ade2e8f71987109b9fb651f0ab9b073bd Mon Sep 17 00:00:00 2001 From: Songki Choi Date: Wed, 30 Aug 2023 13:13:30 +0900 Subject: [PATCH 1/4] Apply AdaptClassLabel op after LoadResizeDataFromOTXDataset Signed-off-by: Songki Choi --- src/otx/algorithms/detection/adapters/mmdet/configurer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/otx/algorithms/detection/adapters/mmdet/configurer.py b/src/otx/algorithms/detection/adapters/mmdet/configurer.py index 8effbb81c61..427e122c10f 100644 --- a/src/otx/algorithms/detection/adapters/mmdet/configurer.py +++ b/src/otx/algorithms/detection/adapters/mmdet/configurer.py @@ -134,7 +134,7 @@ def configure_task_data_pipeline(self, cfg): class_adapt_cfg = dict(type="AdaptClassLabels", src_classes=self.data_classes, dst_classes=self.model_classes) pipeline_cfg = tr_data_cfg.pipeline for i, operation in enumerate(pipeline_cfg): - if operation["type"] == "LoadAnnotationFromOTXDataset": # insert just after this operation + if operation["type"] in ["LoadAnnotationFromOTXDataset", "LoadResizeDataFromOTXDataset"]: # insert just after this operation op_next_ann = pipeline_cfg[i + 1] if i + 1 < len(pipeline_cfg) else {} if op_next_ann.get("type", "") == class_adapt_cfg["type"]: op_next_ann.update(class_adapt_cfg) From e465250e3e2929d060cd06a78a1b2b4219e544b3 Mon Sep 17 00:00:00 2001 From: Songki Choi Date: Wed, 30 Aug 2023 13:13:51 +0900 Subject: [PATCH 2/4] Apply LoadResizeDataFromOTXDataset to validation pipelines Signed-off-by: Songki Choi --- .../configs/base/data/data_pipeline.py | 14 ++++++- .../configs/base/data/atss_data_pipeline.py | 20 ++++++++- .../data/iseg_efficientnet_data_pipeline.py | 22 +++++++++- .../base/data/iseg_resnet_data_pipeline.py | 21 +++++++++- .../cspdarknet_yolox/data_pipeline.py | 42 ++++++++++++------- .../mobilenetv2_ssd/data_pipeline.py | 34 ++++++++------- .../configs/base/data/data_pipeline.py | 25 ++++++++++- 7 files changed, 143 insertions(+), 35 deletions(-) diff --git a/src/otx/algorithms/classification/configs/base/data/data_pipeline.py b/src/otx/algorithms/classification/configs/base/data/data_pipeline.py index 40a05d55467..791b7afe5d1 100644 --- a/src/otx/algorithms/classification/configs/base/data/data_pipeline.py +++ b/src/otx/algorithms/classification/configs/base/data/data_pipeline.py @@ -25,6 +25,7 @@ resize_cfg=dict(type="Resize", size=__resize_target_size, downscale_only=True), # To be resized in this op only if input is larger than expected size # for speed & cache memory efficiency. + enable_memcache=True, # Cache after resizing image ), dict(type="RandomResizedCrop", size=__resize_target_size, efficientnet_style=True), dict(type="RandomFlip", flip_prob=0.5, direction="horizontal"), @@ -51,6 +52,17 @@ ), ] +__val_pipeline = [ + dict( + type="LoadResizeDataFromOTXDataset", + resize_cfg=dict(type="Resize", size=__resize_target_size), + enable_memcache=True, # Cache after resizing image + ), + dict(type="Normalize", **__img_norm_cfg), + dict(type="ImageToTensor", keys=["img"]), + dict(type="Collect", keys=["img"]), +] + __test_pipeline = [ dict(type="LoadImageFromOTXDataset"), dict(type="ResizeTo", size=__resize_target_size), @@ -63,6 +75,6 @@ data = dict( train=dict(type=__dataset_type, pipeline=__train_pipeline), - val=dict(type=__dataset_type, test_mode=True, pipeline=__test_pipeline), + val=dict(type=__dataset_type, test_mode=True, pipeline=__val_pipeline), test=dict(type=__dataset_type, test_mode=True, pipeline=__test_pipeline), ) diff --git a/src/otx/algorithms/detection/configs/base/data/atss_data_pipeline.py b/src/otx/algorithms/detection/configs/base/data/atss_data_pipeline.py index 61d0580684a..6081af30ef0 100644 --- a/src/otx/algorithms/detection/configs/base/data/atss_data_pipeline.py +++ b/src/otx/algorithms/detection/configs/base/data/atss_data_pipeline.py @@ -49,6 +49,24 @@ ], ), ] +val_pipeline = [ + dict( + type="LoadResizeDataFromOTXDataset", + resize_cfg=dict(type="Resize", img_scale=__img_size, keep_ratio=False), + enable_memcache=True, # Cache after resizing image + ), + dict( + type="MultiScaleFlipAug", + img_scale=__img_size, + flip=False, + transforms=[ + dict(type="RandomFlip"), + dict(type="Normalize", **__img_norm_cfg), + dict(type="ImageToTensor", keys=["img"]), + dict(type="Collect", keys=["img"]), + ], + ), +] test_pipeline = [ dict(type="LoadImageFromOTXDataset"), dict( @@ -76,7 +94,7 @@ val=dict( type=__dataset_type, test_mode=True, - pipeline=test_pipeline, + pipeline=val_pipeline, ), test=dict( type=__dataset_type, diff --git a/src/otx/algorithms/detection/configs/base/data/iseg_efficientnet_data_pipeline.py b/src/otx/algorithms/detection/configs/base/data/iseg_efficientnet_data_pipeline.py index 63005cce261..66ef798c1a5 100644 --- a/src/otx/algorithms/detection/configs/base/data/iseg_efficientnet_data_pipeline.py +++ b/src/otx/algorithms/detection/configs/base/data/iseg_efficientnet_data_pipeline.py @@ -50,6 +50,26 @@ ), ] +val_pipeline = [ + dict( + type="LoadResizeDataFromOTXDataset", + resize_cfg=dict(type="Resize", img_scale=__img_size, keep_ratio=False), + enable_memcache=True, # Cache after resizing image + ), + dict( + type="MultiScaleFlipAug", + img_scale=__img_size, + flip=False, + transforms=[ + dict(type="RandomFlip"), + dict(type="Normalize", **__img_norm_cfg), + dict(type="Pad", size_divisor=32), + dict(type="ImageToTensor", keys=["img"]), + dict(type="Collect", keys=["img"]), + ], + ), +] + test_pipeline = [ dict(type="LoadImageFromOTXDataset"), dict( @@ -77,7 +97,7 @@ val=dict( type=__dataset_type, test_mode=True, - pipeline=test_pipeline, + pipeline=val_pipeline, ), test=dict( type=__dataset_type, diff --git a/src/otx/algorithms/detection/configs/base/data/iseg_resnet_data_pipeline.py b/src/otx/algorithms/detection/configs/base/data/iseg_resnet_data_pipeline.py index d5010e6fad7..974f1fe7c93 100644 --- a/src/otx/algorithms/detection/configs/base/data/iseg_resnet_data_pipeline.py +++ b/src/otx/algorithms/detection/configs/base/data/iseg_resnet_data_pipeline.py @@ -49,6 +49,25 @@ ), ] +val_pipeline = [ + dict( + type="LoadResizeDataFromOTXDataset", + resize_cfg=dict(type="Resize", img_scale=__img_size, keep_ratio=False), + enable_memcache=True, # Cache after resizing image + ), + dict( + type="MultiScaleFlipAug", + img_scale=__img_size, + flip=False, + transforms=[ + dict(type="RandomFlip"), + dict(type="Normalize", **__img_norm_cfg), + dict(type="ImageToTensor", keys=["img"]), + dict(type="Collect", keys=["img"]), + ], + ), +] + test_pipeline = [ dict(type="LoadImageFromOTXDataset"), dict( @@ -75,7 +94,7 @@ val=dict( type=__dataset_type, test_mode=True, - pipeline=test_pipeline, + pipeline=val_pipeline, ), test=dict( type=__dataset_type, diff --git a/src/otx/algorithms/detection/configs/detection/cspdarknet_yolox/data_pipeline.py b/src/otx/algorithms/detection/configs/detection/cspdarknet_yolox/data_pipeline.py index 61d26d49ff3..f96975e4ffc 100644 --- a/src/otx/algorithms/detection/configs/detection/cspdarknet_yolox/data_pipeline.py +++ b/src/otx/algorithms/detection/configs/detection/cspdarknet_yolox/data_pipeline.py @@ -1,23 +1,13 @@ """Data Pipeline of YOLOX model for Detection 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. +# Copyright (C) 2022-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 # pylint: disable=invalid-name __img_norm_cfg = dict(mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) __img_size = (640, 640) +__img_size_test = (416, 416) train_pipeline = [ dict(type="Mosaic", img_scale=__img_size, pad_val=114.0), @@ -57,16 +47,36 @@ ), ] +val_pipeline = [ + dict( + type="LoadResizeDataFromOTXDataset", + resize_cfg=dict(type="Resize", img_scale=__img_size_test, keep_ratio=True), + enable_memcache=True, # Cache after resizing image + ), + dict( + type="MultiScaleFlipAug", + img_scale=__img_size_test, + flip=False, + transforms=[ + dict(type="RandomFlip"), + dict(type="Pad", size=__img_size_test, pad_val=114.0), + dict(type="Normalize", **__img_norm_cfg), + dict(type="DefaultFormatBundle"), + dict(type="Collect", keys=["img"]), + ], + ), +] + test_pipeline = [ dict(type="LoadImageFromOTXDataset"), dict( type="MultiScaleFlipAug", - img_scale=(416, 416), + img_scale=__img_size_test, flip=False, transforms=[ dict(type="Resize", keep_ratio=True), dict(type="RandomFlip"), - dict(type="Pad", size=(416, 416), pad_val=114.0), + dict(type="Pad", size=__img_size_test, pad_val=114.0), dict(type="Normalize", **__img_norm_cfg), dict(type="DefaultFormatBundle"), dict(type="Collect", keys=["img"]), @@ -101,7 +111,7 @@ val=dict( type=__dataset_type, test_mode=True, - pipeline=test_pipeline, + pipeline=val_pipeline, ), test=dict( type=__dataset_type, diff --git a/src/otx/algorithms/detection/configs/detection/mobilenetv2_ssd/data_pipeline.py b/src/otx/algorithms/detection/configs/detection/mobilenetv2_ssd/data_pipeline.py index 1494121e514..fe689639c9b 100644 --- a/src/otx/algorithms/detection/configs/detection/mobilenetv2_ssd/data_pipeline.py +++ b/src/otx/algorithms/detection/configs/detection/mobilenetv2_ssd/data_pipeline.py @@ -1,18 +1,7 @@ """Data Pipeline of SSD model for Detection 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. +# Copyright (C) 2022-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 # pylint: disable=invalid-name @@ -63,6 +52,23 @@ ], ), ] +val_pipeline = [ + dict( + type="LoadResizeDataFromOTXDataset", + resize_cfg=dict(type="Resize", img_scale=__img_size, keep_ratio=False), + enable_memcache=True, # Cache after resizing image + ), + dict( + type="MultiScaleFlipAug", + img_scale=__img_size, + flip=False, + transforms=[ + dict(type="Normalize", **__img_norm_cfg), + dict(type="ImageToTensor", keys=["img"]), + dict(type="Collect", keys=["img"]), + ], + ), +] test_pipeline = [ dict(type="LoadImageFromOTXDataset"), dict( @@ -85,7 +91,7 @@ val=dict( type=__dataset_type, test_mode=True, - pipeline=test_pipeline, + pipeline=val_pipeline, ), test=dict( type=__dataset_type, diff --git a/src/otx/algorithms/segmentation/configs/base/data/data_pipeline.py b/src/otx/algorithms/segmentation/configs/base/data/data_pipeline.py index 2203bdaa21f..d1e2a5394e8 100644 --- a/src/otx/algorithms/segmentation/configs/base/data/data_pipeline.py +++ b/src/otx/algorithms/segmentation/configs/base/data/data_pipeline.py @@ -54,6 +54,29 @@ ), ] +val_pipeline = [ + dict( + type="LoadResizeDataFromOTXDataset", + resize_cfg=dict(type="Resize", img_scale=__img_scale, keep_ratio=False), + enable_memcache=True, # Cache after resizing image + use_otx_adapter=True, + ), + dict( + type="MultiScaleFlipAug", + img_scale=__img_scale, + flip=False, + transforms=[ + dict(type="RandomFlip"), + dict(type="Normalize", **__img_norm_cfg), + dict(type="ImageToTensor", keys=["img"]), + dict( + type="Collect", + keys=["img"], + ), + ], + ), +] + test_pipeline = [ dict(type="LoadImageFromOTXDataset", use_otx_adapter=True), dict( @@ -75,6 +98,6 @@ data = dict( train=dict(type="MPASegDataset", pipeline=train_pipeline), - val=dict(type="MPASegDataset", pipeline=test_pipeline), + val=dict(type="MPASegDataset", pipeline=val_pipeline), test=dict(type="MPASegDataset", pipeline=test_pipeline), ) From 234352be521cd3649e9829745f95a15db23e40ef Mon Sep 17 00:00:00 2001 From: Songki Choi Date: Wed, 30 Aug 2023 13:52:59 +0900 Subject: [PATCH 3/4] Fix pickling issue Signed-off-by: Songki Choi --- .../adapters/mmcv/pipelines/load_image_from_otx_dataset.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/otx/algorithms/common/adapters/mmcv/pipelines/load_image_from_otx_dataset.py b/src/otx/algorithms/common/adapters/mmcv/pipelines/load_image_from_otx_dataset.py index a642b09a4d8..444a537d459 100644 --- a/src/otx/algorithms/common/adapters/mmcv/pipelines/load_image_from_otx_dataset.py +++ b/src/otx/algorithms/common/adapters/mmcv/pipelines/load_image_from_otx_dataset.py @@ -191,6 +191,7 @@ def __call__(self, results: Dict[str, Any]) -> Dict[str, Any]: return cached_results results = self._load_img(results) results = self._load_ann_if_any(results) + results.pop("dataset_item", None) # Prevent deepcopy or caching results = self._resize_img_ann_if_any(results) self._save_cache(results) return results From c2893bbe38ed6c73067ffcd30891db822cf85c44 Mon Sep 17 00:00:00 2001 From: Songki Choi Date: Wed, 30 Aug 2023 13:57:06 +0900 Subject: [PATCH 4/4] Fix pre-commit Signed-off-by: Songki Choi --- src/otx/algorithms/detection/adapters/mmdet/configurer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/otx/algorithms/detection/adapters/mmdet/configurer.py b/src/otx/algorithms/detection/adapters/mmdet/configurer.py index 427e122c10f..e16a24cd496 100644 --- a/src/otx/algorithms/detection/adapters/mmdet/configurer.py +++ b/src/otx/algorithms/detection/adapters/mmdet/configurer.py @@ -134,7 +134,10 @@ def configure_task_data_pipeline(self, cfg): class_adapt_cfg = dict(type="AdaptClassLabels", src_classes=self.data_classes, dst_classes=self.model_classes) pipeline_cfg = tr_data_cfg.pipeline for i, operation in enumerate(pipeline_cfg): - if operation["type"] in ["LoadAnnotationFromOTXDataset", "LoadResizeDataFromOTXDataset"]: # insert just after this operation + if operation["type"] in [ + "LoadAnnotationFromOTXDataset", + "LoadResizeDataFromOTXDataset", + ]: # insert just after this operation op_next_ann = pipeline_cfg[i + 1] if i + 1 < len(pipeline_cfg) else {} if op_next_ann.get("type", "") == class_adapt_cfg["type"]: op_next_ann.update(class_adapt_cfg)