Skip to content

Torchvision/fix issue 4295 #7985

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 4 commits into
base: main
Choose a base branch
from

Conversation

vilktor370
Copy link
Contributor

@vilktor370 vilktor370 commented Sep 24, 2023

A new example in the gallery is added as requested in this #4295. This new example is to show the difference between to_tensor, pil_to_tensor, and to_pil_image.

cc @vfdev-5

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 24, 2023

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Unrelated Failure

As of commit caee390 with merge base 35677ec (image):

NEW FAILURE - The following job has failed:

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.

@vilktor370
Copy link
Contributor Author

vilktor370 commented Sep 25, 2023

@NicolasHug

Are there any known issues regarding the CI pipeline? I am not sure why the CI pipeline is failing on Lint. I did ufmt and flake8 locally on that file. Everything seemed to be good to me before I pushed. I guess it's because I added a new entry in conf.py.

@NicolasHug
Copy link
Member

Hi @vilktor370 and thank for the PR.

Quite a bit has changed since we opened #4295 and we have new "preferred" ways of performing these conversions. In particular, we have deprecated ToTensor and we have a new ToImage transform now, that can probably be preferred over PilToImage.

With these new transforms, the overall story should be a bit simpler and probably doesn't require a full-fledge gallery example anymore. I think we can write a small paragraph here https://pytorch.org/vision/main/transforms.html#conversion instead, and explain that:

  • To convert from anything to a tensor, ToImage() can be used (there is also PilToTensor(), but it doesn't support numpy).
  • To convert to a PIL Image, use ToPILImage()
  • To convert the dtype and to scale values of a tensor, ToDtype(dtype, scale=True) can be used
  • ToTensor() is deprecated and shouldn't be used anymore. Compose([ToImage(), ToDtype(torch.float32, scale=True)]) is recommended instead.

Does this make sense?

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.

4 participants