AttributeError when input type has no element_size() method
lueisert opened this issue · comments
The bug
Hi, I see a problem with the code calculating the size of the layers:
In layer_info.py line 109:
if hasattr(inputs[0], "size") and callable(inputs[0].size):
return list(inputs[0].size()), inputs[0].element_size()
I have the problem, that I use a package with modified tensors which have no "element_size" method.
I.e. the code crashes at that point.
Expected behavior
What about this
if hasattr(inputs[0], "size") and callable(inputs[0].size):
if hasattr(inputs[0], "element_size") and callable(inputs[0].element_size):
return list(inputs[0].size()), inputs[0].element_size()
else:
#Maybe add a warning here
return list(inputs[0].size()), 0
Can you link the full code used to get this error? If I do not have a test case I cannot support it going forward.
PRs fixing this are welcome
Hi!
My code is not public atm. I could write a test case if I find some time later this week!
In my case Im using E2-equivariant CNN layers from here https://github.com/QUVA-Lab/e2cnn and they use a modified tensor to handle the equivariance (https://github.com/QUVA-Lab/e2cnn/blob/master/e2cnn/nn/geometric_tensor.py). There is a size() but no element_size() method defined. This said, I could also ask them to add this to their code.
But I think it would be nice if your code would work also for non-supported layers as much as possible and not only return with an error.
Thanks, please submit a test case when you get the chance.