Skip to content
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

Add parameter type to to_tensor #8251

Merged
merged 3 commits into from
Feb 8, 2024
Merged

Conversation

adamtheturtle
Copy link
Contributor

@adamtheturtle adamtheturtle commented Feb 2, 2024

Copy link

pytorch-bot bot commented Feb 2, 2024

🔗 Helpful Links

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

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

✅ You can merge normally! (33 Unrelated Failures)

As of commit fbac810 with merge base 6a936e4 (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@facebook-github-bot
Copy link

Hi @adamtheturtle!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@@ -123,7 +123,7 @@ def _is_numpy_image(img: Any) -> bool:
return img.ndim in {2, 3}


def to_tensor(pic) -> Tensor:
def to_tensor(pic: Image | np.ndarray) -> Tensor:
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the PR @adamtheturtle , I think you'll have to use Union instead of | as | isn't supported in some older Python versions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @NicolasHug . I have updated this PR.

@NicolasHug
Copy link
Member

Thanks @adamtheturtle

Looks like the tests are failing:

  Traceback (most recent call last):
    File "test/smoke_test.py", line 7, in <module>
      import torchvision
    File "/pytorch/vision/torchvision/__init__.py", line 6, in <module>
      from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils
    File "/pytorch/vision/torchvision/datasets/__init__.py", line 23, in <module>
      from .fakedata import FakeData
    File "/pytorch/vision/torchvision/datasets/fakedata.py", line 5, in <module>
      from .. import transforms
    File "/pytorch/vision/torchvision/transforms/__init__.py", line 1, in <module>
      from .transforms import *
    File "/pytorch/vision/torchvision/transforms/transforms.py", line 17, in <module>
      from . import functional as F
    File "/pytorch/vision/torchvision/transforms/functional.py", line 126, in <module>
      def to_tensor(pic: Union[Image, np.ndarray]) -> Tensor:
    File "/opt/conda/envs/ci/lib/python3.8/typing.py", line 261, in inner
      return func(*args, **kwds)
    File "/opt/conda/envs/ci/lib/python3.8/typing.py", line 358, in __getitem__
      parameters = tuple(_type_check(p, msg) for p in parameters)
    File "/opt/conda/envs/ci/lib/python3.8/typing.py", line 358, in <genexpr>
  Traceback (most recent call last):
    File "/home/ec2-user/actions-runner/_work/vision/vision/test-infra/.github/scripts/run_with_env_secrets.py", line 100, in <module>
      main()
    File "/home/ec2-user/actions-runner/_work/vision/vision/test-infra/.github/scripts/run_with_env_secrets.py", line 96, in main
      run_cmd_or_die(f"docker exec -t {container_name} /exec")
    File "/home/ec2-user/actions-runner/_work/vision/vision/test-infra/.github/scripts/run_with_env_secrets.py", line 38, in run_cmd_or_die
      raise RuntimeError(f"Command {cmd} failed with exit code {exit_code}")
  RuntimeError: Command docker exec -t b2f38ee0ffd06ad97f2daef9b2cb4c4e11e74664b2c492e44f4f8edb23f275af /exec failed with exit code 1
      parameters = tuple(_type_check(p, msg) for p in parameters)
    File "/opt/conda/envs/ci/lib/python3.8/typing.py", line 149, in _type_check
      raise TypeError(f"{msg} Got {arg!r:.100}.")
  TypeError: Union[arg, ...]: each arg must be a type. Got <module 'PIL.Image' from '/opt/conda/envs/ci/lib/python3.8/site-packages/PIL/Image.py'>.

I'm going to make this a "draft" PR - when the failures are fixed please ping me again with @NicolasHug so I can take a look! thank you

@NicolasHug NicolasHug marked this pull request as draft February 6, 2024 10:32
@adamtheturtle
Copy link
Contributor Author

@NicolasHug I think we should be good now

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thank you @adamtheturtle

@NicolasHug NicolasHug merged commit 81e2831 into pytorch:main Feb 8, 2024
11 of 31 checks passed
@adamtheturtle
Copy link
Contributor Author

Thank you @NicolasHug for getting this in.

@adamtheturtle adamtheturtle deleted the patch-1 branch February 8, 2024 10:36
facebook-github-bot pushed a commit that referenced this pull request Mar 20, 2024
Summary: Co-authored-by: Nicolas Hug <[email protected]>

Reviewed By: vmoens

Differential Revision: D55062810

fbshipit-source-id: 142052d28b3d5948876ebf63cc64fd3e2f28e37b
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.

3 participants