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

A TypeError occurred while running this code in Colab #120

Closed Bear-Lx closed 4 years ago

Bear-Lx commented 4 years ago

When I was running code in Google Colab, I encountered the following error message: File "capsulenet.py", line 244, in <module>routings=args.routings) File "capsulenet.py", line 50, in CapsNet name='digitcaps')(primarycaps) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py", line 897, in __call__ self._maybe_build(inputs) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py", line 2416, in _maybe_build self.build(input_shapes) # pylint:disable=not-callable File "/content/drive/My Drive/CapsNet_Keras_master/capsulelayers.py", line 116, in build name='W') File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py", line 577, in add_weight caching_device=caching_device) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/base.py", line 743, in _add_variable_with_custom_getter **kwargs_for_getter) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 141, in make_variable shape=variable_shape if variable_shape else None) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py", line 259, in __call__ return cls._variable_v1_call(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py", line 220, in _variable_v1_call shape=shape) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py", line 198, in <lambda> previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variable_scope.py", line 2598, in default_variable_creator shape=shape) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/variables.py", line 263, in __call__ return super(VariableMetaclass, cls).__call__(*args, **kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/resource_variable_ops.py", line 1434, in __init__ distribute_strategy=distribute_strategy) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/resource_variable_ops.py", line 1567, in _init_from_args initial_value() if init_from_fn else initial_value, File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 121, in <lambda> init_val = lambda: initializer(shape, dtype=dtype) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/init_ops_v2.py", line 542, in __call__ fan_in, fan_out = _compute_fans(scale_shape) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/init_ops_v2.py", line 1015, in _compute_fans receptive_field_size *= dim TypeError: unsupported operand type(s) for *=: 'float' and 'NoneType' I'm sure that tensorflow version is 2.2.0, Does anyone have the same problem?

zhangxin9988 commented 3 years ago

same error