Skip to content

Scriptable RandomChoice #7791

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Scriptable RandomChoice #7791

wants to merge 1 commit into from

Conversation

zshn25
Copy link
Contributor

@zshn25 zshn25 commented Aug 1, 2023

This PR brings the following advantages

  • Removes restriction of inputs of RandomChoice of PIL.Image to also include torch.Tensors
  • Makes it JIT Scriptable
  • Replaces the usage of the random module to native torch

The bottleneck was the ModuleList indexing issue: pytorch/pytorch#16123
self.transforms[i.item()](img) gives Error: Expected integer literal for index, while JIT Scripting

Workaround is to iterate over the Modulelist and choose. (O(n) instead of O(1) but works)

@pytorch-bot
Copy link

pytorch-bot bot commented Aug 1, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/7791

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants