Closed jcjview closed 6 years ago
oh, sorry. I has not any experience about theano. it seems that T.nnet.softmax only support 1-d or 2-d tensor. but keras.io do not show it.
I will try to fix it but I am sure about it.
Thanks a lot.
now I change the code, and I build the capsule model successfully with Keras + theano, but error while training with model.fit. I has debuged long time but can not find the reason.
If you can work out, please tell me.
@bojone
Maybe it's about the wrong output shape of the K.batch_dot()
, which is a Runtime Error
for i in range(self.routings):
c = softmax(b, 1)
outputs = self.activation(K.batch_dot(c, u_hat_vecs, [2, 2])) # outputs.shape = [None, num_capsule, num_capsule, dim_capsule]
if i < self.routings - 1:
b = K.batch_dot(outputs, u_hat_vecs, [2, 3])
the outputs
's shape does not match the output of compute_output_shape
.
Best, Yiming
@ymcui c.shape is [None, num_capsule, input_num_capsule] u_hat_vecs.shape = [None, num_capsule, input_num_capsule, dim_capsule] batch_dot of them has shape of [None, num_capsule, dim_capsule] why do you think of [None, num_capsule, num_capsule, dim_capsule] ?
@bojone Maybe you can have a try with toy tensor. The result should be the shape that I have posted. Your error results from the runtime error on shape. Just a quick fix: https://github.com/ymcui/Capsule/blob/master/Capsule_Keras.py
@ymcui you mean batch_dot has a different performance with theano backend?
@ymcui you are right. I got it. thanks very much.
You're welcome :)
when I run "python capsule_test.py",there is some error as follows:
Traceback (most recent call last):
File "capsule_test.py", line 82, in
I update keras,but the error remains,please help me
@wuzy361 which backend?
using tensorflow backend.
when I run "python capsule_test.py",there is some error as follows:
Traceback (most recent call last):
File "capsule_test.py", line 83, in
please help me!Thanks
@zhangjunwang your keras and tensorflow must be updated to lastest version. the problem is resulted from that your tensorflow version is lower than the keras needed.
@bojone Thanks,I will try it.
Traceback (most recent call last):
File "capsule_test.py", line 46, in
capsule = Capsule(10, 16, 3, True)(cnn)
File "/home/.../anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 603, in call
output = self.call(inputs, *kwargs)
File "/data/.../study/Capsule/Capsule_Keras.py", line 60, in call
c = K.softmax(b)
File "/home/.../anaconda3/lib/python3.6/site-packages/keras/backend/theano_backend.py", line 1552, i n softmax
return T.nnet.softmax(x)
File "/home/.../anaconda3/lib/python3.6/site-packages/theano/tensor/nnet/nnet.py", line 809, in soft max
return softmax_op(c)
File "/home/.../anaconda3/lib/python3.6/site-packages/theano/gof/op.py", line 615, in call
node = self.make_node(inputs, **kwargs)
File "/home/.../anaconda3/lib/python3.6/site-packages/theano/tensor/nnet/nnet.py", line 431, in make _node
x.type)
ValueError: x must be 1-d or 2-d tensor of floats. Got TensorType(float32, 3D)
I try tensorflow backend , no error.