Closed QuickLearner171998 closed 4 years ago
This is the exact error:
InvalidArgumentError: Dimensions must be equal, but are 2560 and 10 for 'digit_caps_2/add' (op: 'AddV2') with input shapes: [?,10,10,2560,32], [10,32].
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last) 12 frames
For CIFAR10, you need to uncomment line 122 in train.py and comment line 123 in train.py.
I used the exact train.py file from this repository and ended up in a similar error. I'm using Google Colab with GPU hardware accelerator. The tensorflow version used is 1.15.0.
This is the error message: Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py", line 1607, in _create_c_op c_op = c_api.TF_FinishOperation(op_desc) tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimensions must be equal, but are 640 and 10 for 'digit_caps/add' (op: 'AddV2') with input shapes: [?,10,10,640,32], [10,32].
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "train.py", line 123, in
you need to uncomment line 122 in train.py and comment line 123 in train.py. This is causing the error, DeepCapsNet28 is for MNIST, use DeepCapsNet for CIFAR10.
Hi @brjathu
I got exactly the same error. I am using DeepCapsNet28
for MNIST dataset (however I tried to change toggle comments on lines 122 and 123 without any impact).
I have tested several environments and no one was working. Can you please help me with this error? I think it may be caused by Keras update.
Thanks in advance!
This is the trackback of the error
WARNING:tensorflow:From $HOME/deepcaps/deepcaps/capslayers.py:346: calling softmax (from tensorflow.python.ops.nn_ops) with dim is deprecated and will be removed in a future version.
Instructions for updating:
dim is deprecated, use axis instead
Traceback (most recent call last):
File "$HOME/.conda/envs/snowflakes/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1659, in _create_c_op
c_op = c_api.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimensions must be equal, but are 640 and 10 for 'digit_caps/add' (op: 'Add') with input shapes: [?,10,10,640,32], [10,32].
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "train.py", line 123, in <module>
model, eval_model = DeepCapsNet28(input_shape=x_train.shape[1:], n_class=y_train.shape[1], routings=args.routings) #for 28*28
File "$HOME/deepcaps/deepcaps/deepcaps.py", line 135, in DeepCapsNet28
digits_caps = CapsuleLayer(num_capsule=n_class, dim_capsule=32, routings=routings, channels=0, name='digit_caps')(l)
File "$HOME/.local/lib/python3.6/site-packages/keras/engine/base_layer.py", line 489, in __call__
output = self.call(inputs, **kwargs)
File "$HOME/deepcaps/deepcaps/capslayers.py", line 563, in call
outputs = squash(K.batch_dot(c, inputs_hat, [2, 2]) + self.B) # [None, 10, 16]
File "$HOME/.conda/envs/snowflakes/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 824, in binary_op_wrapper
return func(x, y, name=name)
File "$HOME/.conda/envs/snowflakes/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py", line 365, in add
"Add", x=x, y=y, name=name)
File "$HOME/.conda/envs/snowflakes/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
op_def=op_def)
File "$HOME/.conda/envs/snowflakes/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "$HOME/.conda/envs/snowflakes/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3300, in create_op
op_def=op_def)
File "$HOME/.conda/envs/snowflakes/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1823, in __init__
control_input_ops)
File "$HOME/.conda/envs/snowflakes/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1662, in _create_c_op
raise ValueError(str(e))
ValueError: Dimensions must be equal, but are 640 and 10 for 'digit_caps/add' (op: 'Add') with input shapes: [?,10,10,640,32], [10,32].
This is the list of installed packages (I am using Anaconda)
$ conda list
# packages in environment at $HOME/.conda/envs/snowflakes:
#
# Name Version Build Channel
_tflow_select 2.1.0 gpu anaconda
absl-py 0.9.0 py36_0 anaconda
astor 0.8.0 py36_0 anaconda
blas 1.0 mkl anaconda
c-ares 1.15.0 h7b6447c_1001 anaconda
ca-certificates 2020.1.1 0 anaconda
certifi 2019.11.28 py36_0 anaconda
cudatoolkit 10.0.130 0 anaconda
cudnn 7.6.5 cuda10.0_0 anaconda
cupti 10.0.130 0 anaconda
freetype 2.9.1 h8a8886c_1 anaconda
gast 0.3.3 py_0 anaconda
grpcio 1.27.2 py36hf8bcb03_0 anaconda
h5py 2.10.0 py36h7918eee_0 anaconda
hdf5 1.10.4 hb1b8bf9_0 anaconda
intel-openmp 2020.0 166 anaconda
jpeg 9b habf39ab_1 anaconda
keras-applications 1.0.8 py_0 anaconda
keras-base 2.3.1 py36_0 anaconda
keras-gpu 2.1.6 py36_0 anaconda
keras-preprocessing 1.1.0 py_1 anaconda
ld_impl_linux-64 2.33.1 h53a641e_7 anaconda
libedit 3.1.20181209 hc058e9b_0 anaconda
libffi 3.2.1 h4deb6c0_3 anaconda
libgcc-ng 9.1.0 hdf63c60_0 anaconda
libgfortran-ng 7.3.0 hdf63c60_0 anaconda
libpng 1.6.37 hbc83047_0 anaconda
libprotobuf 3.11.4 hd408876_0 anaconda
libstdcxx-ng 9.1.0 hdf63c60_0 anaconda
libtiff 4.1.0 h2733197_0 anaconda
markdown 3.1.1 py36_0 anaconda
mkl 2019.5 281 anaconda
mkl-service 2.3.0 py36he904b0f_0 anaconda
mkl_fft 1.0.15 py36ha843d7b_0 anaconda
mkl_random 1.1.0 py36hd6b4f25_0 anaconda
mock 4.0.1 py_0 anaconda
ncurses 6.2 he6710b0_0 anaconda
numpy 1.18.1 py36h4f9e942_0 anaconda
numpy-base 1.18.1 py36hde5b4d6_1 anaconda
olefile 0.46 py_0 anaconda
openssl 1.1.1 h7b6447c_0 anaconda
pillow 7.0.0 py36hb39fc2d_0 anaconda
pip 20.0.2 py36_1 anaconda
protobuf 3.11.4 py36he6710b0_0 anaconda
python 3.6.10 h0371630_0 anaconda
pyyaml 5.3 py36h7b6447c_0 anaconda
readline 7.0 h7b6447c_5 anaconda
scipy 1.4.1 py36h0b6359f_0 anaconda
setuptools 45.2.0 py36_0 anaconda
six 1.14.0 py36_0 anaconda
sqlite 3.31.1 h7b6447c_0 anaconda
tensorboard 1.13.1 py36hf484d3e_0 anaconda
tensorflow 1.13.1 gpu_py36h3991807_0 anaconda
tensorflow-base 1.13.1 gpu_py36h8d69cac_0 anaconda
tensorflow-estimator 1.13.0 py_0 anaconda
tensorflow-gpu 1.13.1 h0d30ee6_0 anaconda
termcolor 1.1.0 py36_1 anaconda
tk 8.6.8 hbc83047_0 anaconda
werkzeug 1.0.0 py_0 anaconda
wheel 0.34.2 py36_0 anaconda
xz 5.2.4 h14c3975_4 anaconda
yaml 0.1.7 h96e3832_1 anaconda
zlib 1.2.11 h7b6447c_3 anaconda
zstd 1.3.7 h0b5b093_0 anaconda
Maybe I have found the problem!
Problem was in keras versions. With following modules
keras-base 2.2.4 py36_0
keras-gpu 2.2.4 0
keras-preprocessing 1.1.0 py_1 anaconda
and update in capslayers.py
# self.data_format = K.normalize_data_format(data_format)
self.data_format = conv_utils.normalize_data_format(data_format)
it seems to be working!
I recommend to update README with specification of keras version (in conda install commands) and this update in capslayers.py. I can create a pull request, if you want ;)
Hi @mrazekv, First of all, sorry for the late reply, and Thank you for figuring out the issue. It would be great if can create the pull request.
I am facing this error while training. I have used the following args: class args: numGPU = 1 epochs = 100 batch_size = 8 lr = 0.001 lr_decay = 0.96 lam_recon = 0.4 r = 3 routings = 3 shift_fraction = 0.1 debug = False digit = 5 save_dir = 'model/CIFAR10/13' t = False w = None ep_num = 0 dataset = "CIFAR10"
The error is common to all datasets.