-
Notifications
You must be signed in to change notification settings - Fork 34.2k
[Vision] .to function for ImageProcessors
#20536
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
Changes from 9 commits
1f1ee46
a8053dd
94c2a93
f9045b1
4af5971
e595cdf
4d05a90
4b9fddd
09e4c49
ba94418
f331dac
af0a4c3
da35051
af04179
fee0585
475f5ef
c5b4b37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| is_tensor, | ||
| is_tf_tensor, | ||
| is_torch_device, | ||
| is_torch_dtype, | ||
| is_torch_tensor, | ||
| reshape, | ||
| squeeze, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,24 @@ def is_torch_device(x): | |
| return False if not is_torch_available() else _is_torch_device(x) | ||
|
|
||
|
|
||
| def _is_torch_dtype(x): | ||
| import torch | ||
|
|
||
| if isinstance(x, str): | ||
| if hasattr(torch, x): | ||
| return True | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be more careful -> i.e. to get that attribute, than test if it is indeed a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you mean ?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, Be careful, I always complicate things. You can hold on until sylvain's review.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adapted your suggestion in da35051 ;) |
||
| else: | ||
| return False | ||
| return isinstance(x, torch.dtype) | ||
|
|
||
|
|
||
| def is_torch_dtype(x): | ||
| """ | ||
| Tests if `x` is a torch device or not. Safe to call even if torch is not installed. | ||
|
younesbelkada marked this conversation as resolved.
Outdated
|
||
| """ | ||
| return False if not is_torch_available() else _is_torch_dtype(x) | ||
|
|
||
|
|
||
| def _is_tensorflow(x): | ||
| import tensorflow as tf | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,7 @@ def prepare_feat_extract_dict(self): | |
| class DeiTFeatureExtractionTest(FeatureExtractionSavingTestMixin, unittest.TestCase): | ||
|
|
||
| feature_extraction_class = DeiTFeatureExtractor if is_vision_available() else None | ||
| test_cast_dtype = True | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it needed here for DeiT and not other models?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just waited for everyone's approval on the concept and planned to add it on more models! Probably on the main models only as it may slow down the CI test suite |
||
|
|
||
| def setUp(self): | ||
| self.feature_extract_tester = DeiTFeatureExtractionTester(self) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.