Closed filaPro closed 3 years ago
Thanks for your kind suggestion. I almost agree with you, but there may be only two concerns:
.clone()
should be added after self.tensor on the right side of the equation to avoid your mentioned RuntimError caused by inplace modifications?I'm now running without extra .clone()
. Do we really need it? The proposed replacement of +=
to torch.cat
already avoids this RuntimeError
.
By the way, if you are going to replace +=
here, it also can be fixed in the translate
method of this class.
Hi @filaPro , Thanks for you kind suggestion. Would you like to create a PR to fix that?
OK @filaPro . I just think .clone()
is a general way to avoid the inplace RuntimeError and could protect the original tensor from being unintentionally changed. If without .clone()
could work on your side, you can feel free to create a PR to fix that.
Hi @Tai-Wang ,
I agree that .clone()
is a better solution then replacing all inplace operations in all methods of BaseInstance3DBoxes
and its descendants. So the PR is as simple as adding this .clone()
.
In my opinion the inplace modification of tensor in this line is dangerous for 2 reasons.
It may tend to corrupt ground truth data in
numpy
format. It's hardly believable, but i'm going to explain. The thing is,torch.as_tensor
function in this line doesn't protect thetensor
argument of__init__
from further rewriting of the same memory, allocated bynumpy
. More info can be found in the official documentation of torch.as_tensor. For example, this constructor is called here inindoor_eval
function. So after each validation step thez
coordinate ofgt_anno['gt_boxes_upright_depth']
may be overwritten. One may ask why it doesn't affect current evaluation protocol forSUNRGBD
? The answer is, by coincidence these coordinates are now stored innp.float64
. The bug would be present if that isnp.float32
.In many cases
pytorch
doesn't like inplace modifications of variables under the gradient. It tends toRuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: ...
If I'm not mistaken something and you agree this is a bug, I can send a PR. The possible solution may be: