gaocong13 / Projective-Spatial-Transformers

Generalizing Spatial Transformers to Projective Geometry with Applications to 2D/3D Registration
110 stars 21 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. #3

Closed rassaire closed 3 years ago

rassaire commented 4 years ago

Hi again, @gaocong13 sorry for disturbing a lot but I want this code to run.

I have run ProST_example_regi.py I got this error "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."

help, please.

rassaire commented 4 years ago

maybe it is due to this warning that I got when I ran requirement file?

"ERROR: torchvision 0.4.0 has requirement torch==1.2.0, but you'll have torch 1.3.0 which is incompatible."

gaocong13 commented 4 years ago

Hi, could you help locate this error? It is likely because of the version conflict of torchgeometry package. Pytorch starts to drop the support of using '-' operator while some packages have not updated yet. If you can locate the error with some IDEs, you can simply replace the operator as the error message suggests.

rassaire commented 4 years ago

Hi @gaocong13 I will try to check out.

rassaire commented 4 years ago

thanks

gaocong13 commented 3 years ago

This error comes from the conflict between torchgeometry package and torch tensor. The solution is to modify torchgeometry package source file: torchgeometry/core/conversions.py

Replace line 301-308 with: inv_mask_d0_d1 = ~mask_d0_d1 inv_mask_d0_nd1 = ~mask_d0_nd1 inv_mask_d2 = ~mask_d2 mask_c0 = mask_d2 * mask_d0_d1 mask_c1 = mask_d2 * inv_mask_d0_d1 mask_c2 = inv_mask_d2 * mask_d0_nd1 mask_c3 = inv_mask_d2 * inv_mask_d0_nd1 mask_c0 = mask_c0.view(-1, 1).type_as(q0) mask_c1 = mask_c1.view(-1, 1).type_as(q1) mask_c2 = mask_c2.view(-1, 1).type_as(q2) mask_c3 = mask_c3.view(-1, 1).type_as(q3)