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

RuntimeError: Subtraction, the - operator, with a bool tensor is not supported. If you are trying to invert a mask, use the ~ or logical_not() operator instead. #6

Closed
pablovela5620 opened this issue Aug 17, 2020 · 6 comments

Comments

@pablovela5620
Copy link

pablovela5620 commented Aug 17, 2020

Trying to run the demo using

python demo.py --gpu 0 --stage param --test_epoch 8

Getting the following error

/home/deeplearning/miniconda3/envs/i2l/bin/python /home/deeplearning/0Dev/repos/I2L-MeshNet_RELEASE/demo/demo.py --gpu 0 --stage param --test_epoch 8
>>> Using GPU: 0
/home/deeplearning/0Dev/repos/I2L-MeshNet_RELEASE/main/../common/utils/smplpytorch/smplpytorch/pytorch/smpl_layer.py:41: 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_1595629395347/work/torch/csrc/utils/tensor_numpy.cpp:141.)
  torch.Tensor(smpl_data['betas'].r).unsqueeze(0))
Load checkpoint from /home/deeplearning/0Dev/repos/I2L-MeshNet_RELEASE/output/model_dump/h36_smpl/snapshot_8.pth.tar
Traceback (most recent call last):
  File "/home/deeplearning/0Dev/repos/I2L-MeshNet_RELEASE/demo/demo.py", line 96, in <module>
    out = model(inputs, targets, meta_info, 'test')
  File "/home/deeplearning/miniconda3/envs/i2l/lib/python3.8/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/deeplearning/miniconda3/envs/i2l/lib/python3.8/site-packages/torch/nn/parallel/data_parallel.py", line 153, in forward
    return self.module(*inputs[0], **kwargs[0])
  File "/home/deeplearning/miniconda3/envs/i2l/lib/python3.8/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "../main/model.py", line 76, in forward
    pose_param, shape_param = self.param_regressor(joint_img_from_mesh.detach())
  File "/home/deeplearning/miniconda3/envs/i2l/lib/python3.8/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/deeplearning/0Dev/repos/I2L-MeshNet_RELEASE/main/../common/nets/module.py", line 124, in forward
    pose = tgm.rotation_matrix_to_angle_axis(pose).reshape(-1,72)
  File "/home/deeplearning/miniconda3/envs/i2l/lib/python3.8/site-packages/torchgeometry/core/conversions.py", line 233, in rotation_matrix_to_angle_axis
    quaternion = rotation_matrix_to_quaternion(rotation_matrix)
  File "/home/deeplearning/miniconda3/envs/i2l/lib/python3.8/site-packages/torchgeometry/core/conversions.py", line 302, in rotation_matrix_to_quaternion
    mask_c1 = mask_d2 * (1 - mask_d0_d1)
  File "/home/deeplearning/miniconda3/envs/i2l/lib/python3.8/site-packages/torch/tensor.py", line 396, in __rsub__
    return _C._VariableFunctions.rsub(self, other)
RuntimeError: Subtraction, the `-` operator, with a bool tensor is not supported. If you are trying to invert a mask, use the `~` or `logical_not()` operator instead.

Process finished with exit code 1

I thought maybe it had something to do with the models not having write permission, but I made sure to change that and still encounter this. Anyone else seen this?

@mks0601
Copy link
Owner

mks0601 commented Aug 17, 2020

Ah.. this is because of torchgeometry do not update their kernel code according to the updated pytorch kernel code. I'll add some hacks that I tried in README. Basically, you need to change L301~L304 of anaconda3/lib/python3.8/site-packages/torchgeometry/core/conversion.py to below.

mask_c0 = mask_d2.float() * mask_d0_d1.float()
mask_c1 = mask_d2.float() * (1 - mask_d0_d1.float())
mask_c2 = (1 - mask_d2.float()) * mask_d0_nd1.float()
mask_c3 = (1 - mask_d2.float()) * (1 - mask_d0_nd1.float())

It just changes binary masks to floating masks.

@Anirudh257
Copy link

@pablovela5620 This issue occurs due to torch version 1.2 or higher. On downgrading to torch==1.1, this issue gets resolved for me.

@pablovela5620
Copy link
Author

Didn't get to try downgrading pytorch, but @mks0601 suggestion worked for me! Though probably not ideal, thank you both for the help!

@booker-max
Copy link

@pablovela5620 This issue occurs due to torch version 1.2 or higher. On downgrading to torch==1.1, this issue gets resolved for me.

Hello, I make torch==1.1, but there is a problem with "from contextlib import nullcontext" in the model.py file, "ImportError: cannot import name'nullcontext'", do you know how to solve it,thank you.

@Anirudh257
Copy link

@booker-max I am not sure about this error. But trying the below code by mka should work.

Ah.. this is because of torchgeometry do not update their kernel code according to the updated pytorch kernel code. I'll add some hacks that I tried in README. Basically, you need to change L301~L304 of anaconda3/lib/python3.8/site-packages/torchgeometry/core/conversion.py to below.

mask_c0 = mask_d2.float() * mask_d0_d1.float()
mask_c1 = mask_d2.float() * (1 - mask_d0_d1.float())
mask_c2 = (1 - mask_d2.float()) * mask_d0_nd1.float()
mask_c3 = (1 - mask_d2.float()) * (1 - mask_d0_nd1.float())

It just changes binary masks to floating masks.

@mks0601
Copy link
Owner

mks0601 commented Mar 18, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants