Prototype transforms cleanup#5504
Merged
Merged
Conversation
Contributor
💊 CI failures summary and remediationsAs of commit 448bec2 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
datumbox
reviewed
Mar 1, 2022
facebook-github-bot
pushed a commit
that referenced
this pull request
Mar 5, 2022
Summary: * fix grayscale to RGB for batches * make unsupported types in auto augment a parameter * make auto augment kwargs explicit * add missing error message * add support for specifying probabilites on RandomChoice * remove TODO for deprecating p on random transforms * streamline sample type checking * address comments * split image_size into height and width in auto augment Reviewed By: datumbox Differential Revision: D34579511 fbshipit-source-id: 757663a5a77f229cd1592b4c23dc17c7e8fe4807 Co-authored-by: Vasilis Vryniotis <datumbox@users.noreply.github.com>
vfdev-5
reviewed
Jul 11, 2022
Comment on lines
+39
to
+48
| def _extract_types(sample: Any) -> Iterator[Type]: | ||
| return query_recursively(lambda id, input: type(input), sample) | ||
|
|
||
|
|
||
| def has_any(sample: Any, *types: Type) -> bool: | ||
| return any(issubclass(type, types) for type in _extract_types(sample)) | ||
|
|
||
|
|
||
| def has_all(sample: Any, *types: Type) -> bool: | ||
| return not bool(set(types) - set(_extract_types(sample))) |
Contributor
There was a problem hiding this comment.
@pmeier fyi maybe we could code has_all and has_any using torch tree_flatten and simplify the code:
from typing import Any, Type
from torch.utils._pytree import tree_flatten
def has_any(sample: Any, *types: Type) -> bool:
flat_sample, _ = tree_flatten(sample)
return any(issubclass(type(obj), types) for obj in flat_sample)
def has_all(sample: Any, *types: Type) -> bool:
flat_sample, _ = tree_flatten(sample)
return not bool(set(types) - set([type(obj) for obj in flat_sample]))
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses minor comments from #5500.