mks0601 / I2L-MeshNet_RELEASE

Official PyTorch implementation of "I2L-MeshNet: Image-to-Lixel Prediction Network for Accurate 3D Human Pose and Mesh Estimation from a Single RGB Image", ECCV 2020
MIT License
720 stars 128 forks source link

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 closed 4 years ago

pablovela5620 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

https://stackoverflow.com/questions/45187286/how-do-i-write-a-null-no-op-contextmanager-in-python

The nullcontext can be used in Python 3.7