naturomics / CapsNet-Tensorflow

A Tensorflow implementation of CapsNet(Capsules Net) in paper Dynamic Routing Between Capsules
Apache License 2.0
3.8k stars 1.17k forks source link

ValueError: Dimensions must be equal, but are 16 and 128 for 'sub_3' (op: 'Sub') with input shapes: [128,10,16,784], [128,784]. #4

Closed djoffrey closed 6 years ago

djoffrey commented 6 years ago

Hi,nice work! But I got an error in my local computer:

python train.py
Traceback (most recent call last):
  File "train.py", line 11, in <module>
    capsNet = CapsNet(is_training=cfg.is_training)
  File "/home/joffrey/projects/CapsNet-Tensorflow/capsNet.py", line 16, in __init__
    self.loss()
  File "/home/joffrey/projects/CapsNet-Tensorflow/capsNet.py", line 84, in loss
    squared = tf.square(self.decoded - orgin)
  File "/home/joffrey/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 865, in binary_op_wrapper
    return func(x, y, name=name)
  File "/home/joffrey/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_math_ops.py", line 2629, in _sub
    result = _op_def_lib.apply_op("Sub", x=x, y=y, name=name)
  File "/home/joffrey/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
    op_def=op_def)
  File "/home/joffrey/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2632, in create_op
    set_shapes_for_outputs(ret)
  File "/home/joffrey/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1911, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "/home/joffrey/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1861, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)
  File "/home/joffrey/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 595, in call_cpp_shape_fn
    require_shape_fn)
  File "/home/joffrey/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 659, in _call_cpp_shape_fn_impl
    raise ValueError(err.message)
ValueError: Dimensions must be equal, but are 16 and 128 for 'sub_3' (op: 'Sub') with input shapes: [128,10,16,784], [128,784].

My env version:

Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15)

tensorflow==1.3.0rc2
tensorflow-gpu==1.3.0
Zhanyu-Wang commented 6 years ago

48 # TODO: before reconstruction the input caps2 should do masking to pick 49 # out the activity vector of the correct digit capsule.

That shows the problem. The reconstruction part has to take the label as input.

naturomics commented 6 years ago

@djoffrey @Zhanyu-Wang-AMSS I'm fixing it now, thanks for your remind.