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

TypeError in a tf file #135

Open selingok033 opened 1 year ago

selingok033 commented 1 year ago

I have cloned the project and when I run it directly, I get the following error. I haven't been able to solve the problem yet, so if anyone can help, I would appreciate it if they could share their solution.

Traceback (most recent call last): File "capsulenet.py", line 242, in model, eval_model, manipulate_model = CapsNet(input_shape=x_train.shape[1:], File "capsulenet.py", line 49, in CapsNet digitcaps = CapsuleLayer(num_capsule=n_class, dim_capsule=16, routings=routings, File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 897, in call self._maybe_build(inputs) File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 2416, in _maybe_build self.build(input_shapes) # pylint:disable=not-callable File "/storage/selin/Works/capsnet-keras/capsulelayers.py", line 113, in build self.W = self.add_weight(shape=[self.num_capsule, self.input_num_capsule, File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 560, in add_weight variable = self._add_variable_with_custom_getter( File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/training/tracking/base.py", line 738, in _add_variable_with_custom_getter new_variable = getter( File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 129, in make_variable return tf_variables.VariableV1( File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/ops/variables.py", line 259, in call return cls._variable_v1_call(*args, kwargs) File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/ops/variables.py", line 205, in _variable_v1_call return previous_getter( File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/ops/variables.py", line 198, in previous_getter = lambda kwargs: default_variable_creator(None, *kwargs) File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/ops/variable_scope.py", line 2584, in default_variable_creator return resource_variable_ops.ResourceVariable( File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/ops/variables.py", line 263, in call return super(VariableMetaclass, cls).call(args, *kwargs) File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 1423, in init self._init_from_args( File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 1567, in _init_from_args initial_value() if init_from_fn else initial_value, File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 121, in init_val = lambda: initializer(shape, dtype=dtype) File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/ops/init_ops_v2.py", line 545, in call fan_in, fan_out = _compute_fans(scale_shape) File "/storage/selin/miniconda3/envs/tf2/lib/python3.8/site-packages/tensorflow/python/ops/init_ops.py", line 1422, in _compute_fans receptive_field_size = dim TypeError: unsupported operand type(s) for *=: 'int' and 'NoneType'