XifengGuo / CapsNet-Keras

A Keras implementation of CapsNet in NIPS2017 paper "Dynamic Routing Between Capsules". Now test error = 0.34%.
MIT License
2.47k stars 651 forks source link

unsupported operand type #105

Closed anshdavid closed 4 years ago

anshdavid commented 4 years ago

I was running thecapsulelayers.py with the default settings., but i get the following error. Guidance would be really appreciated

tensorflow-gpu 2.1.0 keras-gpu 2.3.1

Traceback (most recent call last):
File "capsulenet.py", line 250, in <module>
routings=args.routings)
File "capsulenet.py", line 56, in CapsNet
name='digitcaps')(primarycaps)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 748, in __call__
self._maybe_build(inputs)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 2116, in _maybe_build
self.build(input_shapes)
File "/home/ironwolf1990/codebase/python/capsnet-keras/capsulelayers.py", line 116, in build
name='W')
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 446, in add_weight
caching_device=caching_device)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/training/tracking/base.py", line 744, in _add_variable_with_custom_getter
**kwargs_for_getter)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer_utils.py", line 142, in make_variable
shape=variable_shape if variable_shape else None)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/variables.py", line 258, in __call__
return cls._variable_v1_call(*args, **kwargs)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/variables.py", line 219, in _variable_v1_call
shape=shape)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/variables.py", line 197, in <lambda>
previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/variable_scope.py", line 2596, in default_variable_creator
shape=shape)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/variables.py", line 262, in __call__
return super(VariableMetaclass, cls).__call__(*args, **kwargs)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/resource_variable_ops.py", line 1411, in __init__
distribute_strategy=distribute_strategy)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/resource_variable_ops.py", line 1542, in _init_from_args
initial_value() if init_from_fn else initial_value,
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer_utils.py", line 122, in <lambda>
init_val = lambda: initializer(shape, dtype=dtype)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/init_ops_v2.py", line 409, in __call__
fan_in, fan_out = _compute_fans(scale_shape)
File "/home/ironwolf1990/software/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/init_ops_v2.py", line 735, in _compute_fans
receptive_field_size *= dim
TypeError: unsupported operand type(s) for *=: 'float' and 'NoneType'
rhwas commented 4 years ago

@ironWolf1990 I am also having this issue. I am using same version tensorflow and keras. Any solution found for this?

anshdavid commented 4 years ago

@starcreep48 not yet

XifengGuo commented 4 years ago

@starcreep48 @ironWolf1990 Please check this out: https://github.com/XifengGuo/CapsNet-Keras/tree/tf2.2 I did not fully test it due to the limitation of my current working environment. If it does not work, let me know.

anshdavid commented 4 years ago

@XifengGuo thank you for the update. I'll test it asap and let you know.

RKhur commented 4 years ago

I'm having the same issue pop up with the 2.2 update and the latest code. Did anyone find a fix?

bklooste commented 4 years ago

I got 2.2 to work eg google colab https://github.com/bklooste/tensorflowcollab/blob/master/CapsuleNet_tf2_MNIST.ipynb

but got the same error when i change the model a bit , I think its because the batch size is baked into the model.

openamiguel commented 4 years ago

@XifengGuo I was able to run the code in the tf2.2 branch (Google Cloud VM with one GPU, running Ubuntu 16.04).

anshdavid commented 4 years ago

@XifengGuo used your code as a reference to implement in pytorch. Thanks !