A change in torch\nn\functional might have change usability of the nonzero function used in fasterrcnn_resnet50_fpn. This produces a warning and slows down processing.
Steps to reproduce the behavior:
Produces the following message
C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\functional.py:2854: UserWarning: The default behavior for interpolate/upsample with float scale_factor will change in 1.6.0 to align with other frameworks/libraries, and use scale_factor directly, instead of relying on the computed output size. If you wish to keep the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details.
warnings.warn("The default behavior for interpolate/upsample with float scale_factor will change "
..\torch\csrc\utils\python_arg_parser.cpp:756: UserWarning: This overload of nonzero is deprecated:
nonzero(Tensor input, *, Tensor out)
Consider using one of the following signatures instead:
nonzero(Tensor input, *, bool as_tuple)
The warning is not expected and there is a considerable slowdown compared with previous iterations. I cannot quantify this properly but I have noticed that a task that took +- 5 minutes now takes more than 10.
Please copy and paste the output from our
environment collection script
(or fill out the checklist below manually).
You can get the script and run it with:
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
conda, pip, source): condaThanks for opening the issue!
I would be surprised that the warning would account for such a large slowdown, but changing the code to use the non-deprecated codepaths sounds good to me.
A PR fixing this would be awesome!
Facing the same issue with torchvision.models.detection.keypointrcnn_resnet50_fpn pretrained network. Processing speed is reduced greatly because of the changes in torch.nn.functional.
PyTorch version: 1.5.0
torchvision version: 0.6.0
CPU: Intel i5 8th Gen
OS: Ubuntu 18.04 LTS
Python: 3.7
A fix to stop this warning from triggering would really be appreciated. Thanks!
I runned collect_env.py and get printed output.
Now, what should I copy and where should I paste it?
@sykimm copy and paste on github the output of collect_env.py, although I'm not sure if the slowdown is due to the nonzero warning or the Upsample warning
@fmassa I'm new to this but I'm keen on contributing and perhaps being able to fix this issue. Having checked repository and the warning, would simply setting recompute_scale_factor = True in the forward function help?
@java-abhinav07 yes, it would help, but one would need to verify that it doesn't change the behavior of the code so that old models still give the same result
@fmassa I'll try it locally and get back
Managed to remove recompute_scale_factor warning. However, the TAT is still high possibly because I'm still getting the overload of nonzero warning. Will create a PR once that's fixed...
> /pytorch/torch/csrc/utils/python_arg_parser.cpp:756: UserWarning: This overload of nonzero is deprecated:
> nonzero(Tensor input, *, Tensor out)
> Consider using one of the following signatures instead:
> nonzero(Tensor input, *, bool as_tuple)
PS: The model performance is still the same, verified on multiple images
So seems like the overhead is in nonzero, could you try to see if you could first send a PR changing the nonzero behavior to be the non-deprecated one?
Yes, will fix it asap and send in a PR. Albeit, I did take a quick look and it seems like torch.nonzero has been used at multiple places, having changed the same at a couple of instances the time (for my application) was reduced by 0.5s.
https://github.com/pytorch/vision/pull/2314
@fmassa Kindly review the PR, I will add a separate PR for the recompute_scale_factor warning. This fixes the non-zero depreciation warning issue, thanks! and sorry about the delay
ValueError: All bounding boxes should have positive height and width. Found invaid box [500.728515625, 533.3333129882812, 231.10546875, 255.2083282470703] for target at index 0.
i am getting this error using detecto for object detection
@kashf99 this is the same as https://github.com/pytorch/vision/issues/2740.
@java-abhinav07 Thanks for helping to improve the code. Did you already fix the recompute_scale_factor warning?
Most helpful comment
Yes, will fix it asap and send in a PR. Albeit, I did take a quick look and it seems like torch.nonzero has been used at multiple places, having changed the same at a couple of instances the time (for my application) was reduced by 0.5s.