CapsNet-Keras: ValuerError

Traceback (most recent call last): File “capsulenet.py”, line 310, in <module> routings=args.routings, File “capsulenet.py”, line 60, in CapsNet )(primarycaps) File “/home/Anselmoo/.local/lib/python3.6/site-packages/keras/engine/base_layer.py”, line 489, in call output = self.call(inputs, **kwargs) File “/home/Anselmoo/GitHub-Projects/CapsNet-Keras/capsule/capsulelayers.py”, line 160, in call b += K.batch_dot(outputs, inputs_hat, [2, 3]) File “/home/Anselmoo/.local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py”, line 1499, in batch_dot ‘y.shape[%d] (%d != %d).’ % (axes[0], axes[1], d1, d2))

ValueError: Can not do batch_dot on inputs with shapes (None, 10, 10, 1152, 16) and (None, 10, None, 1152, 16) with axes=[2, 3]. x.shape[2] != y.shape[3] (10 != 1152).

I was running the capsulelayers.py with the default settings.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (1 by maintainers)

Most upvoted comments

@uchar @Anselmoo @mrtucar @data-hound @gcfengxu The problem is caused by the behavior change of keras.backend.batch_dot. In keras==2.0.7: a.shape->(2, 3, 4, 5), b.shape->(2, 3, 5, 6), batch_dot(a, b, (3, 2)).shape->(2, 3, 4, 6).
But in newer version: batch_dot(a, b, (3, 2)).shape->(2, 3, 4, 3, 6)

I propose to replace K.batch_dot with tf.matmul. For details please refer to https://github.com/XifengGuo/CapsNet-Keras/blob/9d7e641e3f30f0e8227bb6ad521a61e908c2408a/capsulelayers.py#L120-L163

@Anselmoo Sorry,I don’t quite understand what you mean.I just copy the ‘batchdot.py’ , add it to my project,and import the file,then replace all ‘K.map_fn()’ with ‘own_batch_dot()’. I haven’t analyzed how the function works.

@Anselmoo Well, I am new to Github,I’ll try your advice,thx for your suggestions!