Skip to content

Add RandomOrder#5534

Merged
wyli merged 15 commits into
Project-MONAI:devfrom
KumoLiu:compose-random-order
Nov 24, 2022
Merged

Add RandomOrder#5534
wyli merged 15 commits into
Project-MONAI:devfrom
KumoLiu:compose-random-order

Conversation

@KumoLiu

@KumoLiu KumoLiu commented Nov 16, 2022

Copy link
Copy Markdown
Contributor

Part of #5517.

Description

When we have a list of transforms, we may want these transforms to do in random order. Add RandomOrder which is a subclass of Compose to provide the ability to apply a list of transformations in random order.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
@KumoLiu KumoLiu requested review from Nic-Ma, ericspod, rijobro and wyli and removed request for rijobro November 16, 2022 10:50

@wyli wyli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

code looks good to me, I'm not sure about the class name RandomOrder, to me the operation is similar with np.random.shuffle https://numpy.org/doc/stable/reference/random/generated/numpy.random.shuffle.html

@KumoLiu

KumoLiu commented Nov 17, 2022

Copy link
Copy Markdown
Contributor Author

code looks good to me, I'm not sure about the class name RandomOrder, to me the operation is similar with np.random.shuffle https://numpy.org/doc/stable/reference/random/generated/numpy.random.shuffle.html

Yes, actually I'm referring to the name of torchvision.
https://pytorch.org/vision/stable/_modules/torchvision/transforms/transforms.html#RandomOrder

@wyli

wyli commented Nov 17, 2022

Copy link
Copy Markdown
Contributor

code looks good to me, I'm not sure about the class name RandomOrder, to me the operation is similar with np.random.shuffle https://numpy.org/doc/stable/reference/random/generated/numpy.random.shuffle.html

Yes, actually I'm referring to the name of torchvision. https://pytorch.org/vision/stable/_modules/torchvision/transforms/transforms.html#RandomOrder

Ok, that's also implemented with a 'shuffle'. Any particular reason that permutation is used in this implementation?

Comment thread tests/test_random_order.py Outdated
@KumoLiu

KumoLiu commented Nov 17, 2022

Copy link
Copy Markdown
Contributor Author

code looks good to me, I'm not sure about the class name RandomOrder, to me the operation is similar with np.random.shuffle https://numpy.org/doc/stable/reference/random/generated/numpy.random.shuffle.html

Yes, actually I'm referring to the name of torchvision. https://pytorch.org/vision/stable/_modules/torchvision/transforms/transforms.html#RandomOrder

Ok, that's also implemented with a 'shuffle'. Any particular reason that permutation is used in this implementation?

Yes, since self. transforms is tuple object, which does not support item assignment.

self.transforms = ensure_tuple(transforms)

Thanks!

@wyli

wyli commented Nov 17, 2022

Copy link
Copy Markdown
Contributor

code looks good to me, I'm not sure about the class name RandomOrder, to me the operation is similar with np.random.shuffle https://numpy.org/doc/stable/reference/random/generated/numpy.random.shuffle.html

Yes, actually I'm referring to the name of torchvision. https://pytorch.org/vision/stable/_modules/torchvision/transforms/transforms.html#RandomOrder

Ok, that's also implemented with a 'shuffle'. Any particular reason that permutation is used in this implementation?

Yes, since self. transforms is tuple object, which does not support item assignment.

self.transforms = ensure_tuple(transforms)

Thanks!

Since the transforms are changed at every iteration, perhaps change it to a list and then shuffle the list is more efficient

Comment thread monai/transforms/compose.py
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Signed-off-by: KumoLiu <yunl@nvidia.com>
Comment thread monai/transforms/compose.py Outdated
@KumoLiu KumoLiu requested a review from wyli November 24, 2022 07:40

@wyli wyli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, it looks good to me.

@wyli

wyli commented Nov 24, 2022

Copy link
Copy Markdown
Contributor

/build

@wyli wyli merged commit cab8fbb into Project-MONAI:dev Nov 24, 2022
@KumoLiu KumoLiu mentioned this pull request Nov 25, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants