-
Notifications
You must be signed in to change notification settings - Fork 446
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
Turn on/off classification augmentations #4039
Merged
goodsong81
merged 7 commits into
openvinotoolkit:develop
from
goodsong81:feat/config-aug/cls-recipe
Oct 18, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a1afb80
Add 'enable' flag for transforms for on/off (default=True)
goodsong81 a14acad
Add common augmentations w/ disabled by default
goodsong81 bacc28e
Add aug combination intg tests for cls
goodsong81 f7218d9
Update change log
goodsong81 032acb6
Merge remote-tracking branch 'upstream/develop' into feat/config-aug/…
goodsong81 33485ce
Update test
goodsong81 a7b72ac
Fix pre-commit
goodsong81 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -42,10 +42,20 @@ overrides: | |
- class_path: otx.core.data.transform_libs.torchvision.EfficientNetRandomCrop | ||
init_args: | ||
scale: $(input_size) | ||
- class_path: otx.core.data.transform_libs.torchvision.PhotoMetricDistortion | ||
enable: false | ||
- class_path: otx.core.data.transform_libs.torchvision.RandomAffine | ||
enable: false | ||
- class_path: otx.core.data.transform_libs.torchvision.RandomFlip | ||
init_args: | ||
prob: 0.5 | ||
is_numpy_to_tvtensor: true | ||
- class_path: torchvision.transforms.v2.RandomVerticalFlip | ||
enable: false | ||
- class_path: torchvision.transforms.v2.GaussianBlur | ||
enable: false | ||
init_args: | ||
kernel_size: 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feature for now will not have possibility to change parameters, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, right. But in this phase, it's a bit limited due to the UX. |
||
- class_path: torchvision.transforms.v2.ToDtype | ||
init_args: | ||
dtype: ${as_torch_dtype:torch.float32} | ||
|
@@ -54,3 +64,5 @@ overrides: | |
init_args: | ||
mean: [123.675, 116.28, 103.53] | ||
std: [58.395, 57.12, 57.375] | ||
- class_path: torchvision.transforms.v2.GaussianNoise | ||
enable: false |
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
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,93 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
import itertools | ||
|
||
import pytest | ||
from datumaro import Dataset as DmDataset | ||
from otx.core.config.data import SamplerConfig, SubsetConfig | ||
from otx.core.data.factory import OTXDatasetFactory | ||
from otx.core.data.mem_cache import MemCacheHandlerSingleton | ||
from otx.core.types.task import OTXTaskType | ||
from otx.engine.utils.auto_configurator import AutoConfigurator | ||
|
||
|
||
def _test_augmentation( | ||
recipe: str, | ||
target_dataset_per_task: dict, | ||
configurable_augs: list[str], | ||
) -> None: | ||
# Load recipe | ||
recipe_tokens = recipe.split("/") | ||
model_name = recipe_tokens[-1].split(".")[0] | ||
task_name = recipe_tokens[-2] | ||
task = OTXTaskType(task_name.upper()) | ||
config = AutoConfigurator( | ||
data_root=target_dataset_per_task[task_name], | ||
task=task, | ||
model_name=model_name, | ||
).config | ||
train_config = config["data"]["train_subset"] | ||
train_config["input_size"] = (32, 32) | ||
|
||
# Load dataset | ||
dm_dataset = DmDataset.import_from( | ||
target_dataset_per_task[task_name], | ||
format=config["data"]["data_format"], | ||
) | ||
mem_cache_handler = MemCacheHandlerSingleton.create( | ||
mode="sinlgeprocessing", | ||
mem_size=0, | ||
) | ||
|
||
# Evaluate all on/off aug combinations | ||
img_shape = None | ||
for switches in itertools.product([True, False], repeat=len(configurable_augs)): | ||
# Configure on/off | ||
for aug_name, switch in zip(configurable_augs, switches): | ||
aug_found = False | ||
for aug_config in train_config["transforms"]: | ||
if aug_name in aug_config["class_path"]: | ||
aug_config["enable"] = switch | ||
aug_found = True | ||
break | ||
assert aug_found, f"{aug_name} not found in {recipe}" | ||
# Create dataset | ||
dataset = OTXDatasetFactory.create( | ||
task=task, | ||
dm_subset=dm_dataset, | ||
cfg_subset=SubsetConfig(sampler=SamplerConfig(**train_config.pop("sampler", {})), **train_config), | ||
mem_cache_handler=mem_cache_handler, | ||
) | ||
|
||
# Check if all aug combinations are size-compatible | ||
data = dataset[0] | ||
if not img_shape: | ||
img_shape = data.img_info.img_shape | ||
else: | ||
assert img_shape == data.img_info.img_shape | ||
|
||
|
||
CLS_RECIPES = [ | ||
recipe for recipe in pytest.RECIPE_LIST if "_cls" in recipe and "semi" not in recipe and "tv_" not in recipe | ||
] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"recipe", | ||
CLS_RECIPES, | ||
) | ||
def test_augmentation_cls( | ||
recipe: str, | ||
fxt_target_dataset_per_task: dict, | ||
): | ||
configurable_augs = [ | ||
"PhotoMetricDistortion", | ||
"RandomAffine", | ||
"RandomVerticalFlip", | ||
"GaussianBlur", | ||
"GaussianNoise", | ||
] | ||
_test_augmentation(recipe, fxt_target_dataset_per_task, configurable_augs) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to keep both RandomFlip (horizontal) and RandomVerticalFlip? I think horizontal flip is more common. Will these augmentations also be used for other tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No requirement for augmentation list, but I've collected some from other solutions.