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

Replace byte tensor #3813

Merged
merged 2 commits into from
May 20, 2021
Merged

Replace byte tensor #3813

merged 2 commits into from
May 20, 2021

Conversation

vipyoung
Copy link
Contributor

replaced the deprecated byteTensor call with from_numpy.
Also slightly refactored the code.

@facebook-github-bot
Copy link

Hi @vipyoung!

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 cla@fb.com. Thanks!

@vfdev-5
Copy link
Collaborator

vfdev-5 commented May 11, 2021

@datumbox thanks for pinging.
There is a list of issues talking about removing torch.ByteTensor(torch.ByteStorage.from_buffer(pic.tobytes())) :

@fmassa even self-assigned himself to fix #3666 , I let him review this PR as well.

@vipyoung this flake8 failure is related : https://app.circleci.com/pipelines/github/pytorch/vision/8023/workflows/9179c017-9365-410e-8959-e77c94a37c26/jobs/571724

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

The code looks great, thanks a lot @vipyoung !

There are lint failures in https://app.circleci.com/pipelines/github/pytorch/vision/8023/workflows/9179c017-9365-410e-8959-e77c94a37c26/jobs/571724 , can you look into fixing those so that we can merge the PR?

Additionally, one thing we might want to consider as well is that we now get the following warning for the uint8 use-case (which we didn't have before)

  /root/project/torchvision/transforms/functional.py:129: UserWarning: The given NumPy array is not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at  /opt/conda/conda-bld/pytorch_1620716760038/work/torch/csrc/utils/tensor_numpy.cpp:180.)
    np.array(pic, mode_to_nptype.get(pic.mode, np.uint8), copy=False)

see https://app.circleci.com/pipelines/github/pytorch/vision/8023/workflows/5620d2f7-08be-493d-9878-fcb5db93539f/jobs/571690 for one example.

We might want think if we want to perform the copy here (which will be less efficient), or suppress this warning somehow.

Thoughts @vfdev-5 ?

Copy link
Contributor Author

@vipyoung vipyoung left a comment

Choose a reason for hiding this comment

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

I've fixed the lint issues and enabled copy of the array here as a quick fix to the warning.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

replaced byteTensor with from_numpy

fixed lint issues and copy related worning
@fmassa fmassa merged commit 7b87af2 into pytorch:master May 20, 2021
facebook-github-bot pushed a commit that referenced this pull request May 25, 2021
Summary:
replaced byteTensor with from_numpy

fixed lint issues and copy related worning

Reviewed By: vincentqb, cpuhrsch

Differential Revision: D28677160

fbshipit-source-id: b508d40651e6e7453e8855fed9edc4f313c7580f

Co-authored-by: Sofiane Abbar <sofa@fb.com>
Co-authored-by: Vasilis Vryniotis <datumbox@users.noreply.github.com>
jithunnair-amd added a commit to ROCm/vision that referenced this pull request Nov 29, 2021
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.

None yet

5 participants