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

Enable to use input_size at transforms in recipe #3759

Merged
merged 15 commits into from
Jul 24, 2024

Conversation

eunwoosh
Copy link
Contributor

@eunwoosh eunwoosh commented Jul 23, 2024

Summary

This PR enables to use input_size at transforms in recipe.
It's for unified input size. So, if value of all init_args in recipe uses input_size, all necessary values are automatically updated by changing only input_size.
For example, let's assume that we have recipe as below.

  data:
    train_subset:
      transforms:
        - class_path: otx.core.data.transform_libs.torchvision.RandomResize
          init_args:
            scale
            - 1000
            - 1000
        - class_path: otx.core.data.transform_libs.torchvision.RandomCrop
          init_args:
            crop_size
            - 500
            - 500

It can be changed as below using input_size.

  data:
    input_size:
    - 1000
    - 1000
    train_subset:
      transforms:
        - class_path: otx.core.data.transform_libs.torchvision.RandomResize
          init_args:
            scale: $(inputs_size)
        - class_path: otx.core.data.transform_libs.torchvision.RandomCrop
          init_args:
            crop_size: $(input_size) * 0.5

As you can see above, $(input_size) should be used to notify to use input_size.
Only simple multiplication or division evaluation is supported. So, addition or subtraction can't be used.
Type of input_size can be int or tuple[int, int]. If int value is given, it's considered as tuple[int, int] with same value.
whether passing int or tuple[int, int] to transform class is decided based on type hint. If there is no type hint, tuple[int, int] is passed.

input_size can be overrided by subset config. For example, if we want to use (1000, 1000) input size at train and (800, 800) at validation, recipe below can be used.

  data:
    input_size:
    - 1000
    - 1000
    train_subset:
      transforms:
        - class_path: otx.core.data.transform_libs.torchvision.RandomResize
          init_args:
            scale: $(inputs_size)
    val_subset:
      input_size:
      - 800
      - 800
      transforms:
        - class_path: otx.core.data.transform_libs.torchvision.RandomResize
          init_args:
            scale: $(inputs_size)

Of course, setting input_size only in subset confg rather than data config is available.
But input_size can't use $(input_size). It's available only in transforms.

How to test

Checklist

  • I have added unit tests to cover my changes.​
  • I have added integration tests to cover my changes.​
  • I have ran e2e tests and there is no issues.
  • I have added the description of my changes into CHANGELOG in my target branch (e.g., CHANGELOG in develop).​
  • I have updated the documentation in my target branch accordingly (e.g., documentation in develop).
  • I have linked related issues.

License

  • I submit my code changes under the same Apache License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below).
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

@github-actions github-actions bot added DEPENDENCY Any changes in any dependencies (new dep or its version) should be produced via Change Request on PM TEST Any changes in tests BUILD OTX 2.0 labels Jul 23, 2024
@eunwoosh eunwoosh force-pushed the unified_input_size branch from a1f8726 to 77fbb0f Compare July 23, 2024 09:12
@github-actions github-actions bot added the DOC Improvements or additions to documentation label Jul 23, 2024
@eunwoosh eunwoosh changed the title Unified input size Enable to use input_size at transforms in reipce Jul 23, 2024
@eunwoosh eunwoosh changed the title Enable to use input_size at transforms in reipce Enable to use input_size at transforms in recipe Jul 23, 2024
goodsong81
goodsong81 previously approved these changes Jul 24, 2024
Copy link
Contributor

@goodsong81 goodsong81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite nice feature for recipe users or developers.
Generally looks good, but it might be controversial if it's "too much".
Left minor comments from a code reader's viewpoint. Feel free to ignore.

src/otx/core/utils/utils.py Outdated Show resolved Hide resolved
src/otx/core/data/transform_libs/torchvision.py Outdated Show resolved Hide resolved
src/otx/core/data/transform_libs/torchvision.py Outdated Show resolved Hide resolved
Copy link
Contributor

@sungchul2 sungchul2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your hard work. :)
I left some comments, please take a look.
And I think this PR has to include updated recipes to check unit and integration tests that are affected by this change.
What do you think?

CHANGELOG.md Outdated Show resolved Hide resolved
src/otx/core/data/transform_libs/torchvision.py Outdated Show resolved Hide resolved
src/otx/core/data/transform_libs/torchvision.py Outdated Show resolved Hide resolved
src/otx/core/data/transform_libs/torchvision.py Outdated Show resolved Hide resolved
src/otx/core/data/transform_libs/torchvision.py Outdated Show resolved Hide resolved
@eunwoosh eunwoosh enabled auto-merge July 24, 2024 09:14
@eunwoosh eunwoosh added this pull request to the merge queue Jul 24, 2024
Merged via the queue into openvinotoolkit:develop with commit 821c808 Jul 24, 2024
18 checks passed
@eunwoosh eunwoosh deleted the unified_input_size branch July 24, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUILD DEPENDENCY Any changes in any dependencies (new dep or its version) should be produced via Change Request on PM DOC Improvements or additions to documentation TEST Any changes in tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants