Skip to content

Add RandomOrder#5534

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

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

Conversation

@KumoLiu
Copy link
Copy Markdown
Contributor

@KumoLiu KumoLiu commented Nov 16, 2022

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 <[email protected]>
Signed-off-by: KumoLiu <[email protected]>
Signed-off-by: KumoLiu <[email protected]>
Signed-off-by: KumoLiu <[email protected]>
Signed-off-by: KumoLiu <[email protected]>
@KumoLiu KumoLiu requested review from Nic-Ma, ericspod, rijobro and wyli and removed request for rijobro November 16, 2022 10:50
Copy link
Copy Markdown
Contributor

@wyli wyli left a comment

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
Copy link
Copy Markdown
Contributor Author

KumoLiu commented Nov 17, 2022

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Nov 17, 2022

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?

@KumoLiu
Copy link
Copy Markdown
Contributor Author

KumoLiu commented Nov 17, 2022

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
Copy link
Copy Markdown
Contributor

wyli commented Nov 17, 2022

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

@KumoLiu KumoLiu requested a review from wyli November 24, 2022 07:40
Copy link
Copy Markdown
Contributor

@wyli wyli left a comment

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
Copy link
Copy Markdown
Contributor

wyli commented Nov 24, 2022

/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