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

Issue: 1916 UserWarning: This overload of nonzero is deprecated: (Solved) #1974

Closed
wants to merge 2 commits into from

Conversation

meetgandhi123
Copy link

The warning was because of the PyTorch function nonzero. This warning can be removed by adding the as_tuple argument in the function.

In the Detectron2/layers/wrappers.py:

"return x.nonzero().unbind(1)" needs to be replaced by
"return torch.nonzero(x, as_tuple=True)"

And in the file Detectron2/modeling/roi_heads/fast_rcnn.py:

"filter_inds = filter_mask.nonzero()" needs to be replaced by
"filter_inds=torch.nonzero(filter_mask, as_tuple=False)"

@facebook-github-bot
Copy link
Contributor

Hi @meetgandhi123!

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.

In order for us to review and merge your code, 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.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 28, 2020
@facebook-github-bot
Copy link
Contributor

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

@ppwwyyxx
Copy link
Contributor

It breaks the test due to pytorch/pytorch#38718.
Maybe you can workaround it with some if is_scripting check.

@john2020-210
Copy link

The warning was because of the PyTorch function nonzero. This warning can be removed by adding the as_tuple argument in the function.

In the Detectron2/layers/wrappers.py:

"return x.nonzero().unbind(1)" needs to be replaced by
"return torch.nonzero(x, as_tuple=True)"

And in the file Detectron2/modeling/roi_heads/fast_rcnn.py:

"filter_inds = filter_mask.nonzero()" needs to be replaced by
"filter_inds=torch.nonzero(filter_mask, as_tuple=False)"

Thank you for your answer ,I have solved the problem flowing your answer!

@Francis0625
Copy link

The same UserWarning in detectron2/structures/masks.py
PYTORCH1.6

/Home/detectron2/detectron2/structures/masks.py:348: UserWarning: This overload of nonzero is deprecated:
nonzero()
Consider using one of the following signatures instead:
nonzero(*, bool as_tuple) (Triggered internally at /pytorch/torch/csrc/utils/python_arg_parser.cpp:766.)
item = item.nonzero().squeeze(1).cpu().numpy().tolist()

Solution:
item = item.nonzero(as_tuple=True).squeeze(1).cpu().numpy().tolist()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants