Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue on manipulate_latent(manipulate_model, (x_test, y_test), args) at tf 2.2 gpu #123

Open
dolannachina opened this issue Dec 19, 2020 · 1 comment

Comments

@dolannachina
Copy link

I train capsule at --epochs 50 --batch_size 400 --routings 3 --lam_recon 0.392
then got a "trained_model.h5"

but when python capsulenet.py -t -w result/trained_model.h5
I will got message:

Model: "functional_1"


Layer (type) Output Shape Param # Connected to

input_1 (InputLayer) [(400, 28, 28, 1)] 0


conv1 (Conv2D) (400, 20, 20, 256) 20992 input_1[0][0]


primarycap_conv2d (Conv2D) (400, 6, 6, 256) 5308672 conv1[0][0]


primarycap_reshape (Reshape) (400, 1152, 8) 0 primarycap_conv2d[0][0]


primarycap_squash (Lambda) (400, 1152, 8) 0 primarycap_reshape[0][0]


digitcaps (CapsuleLayer) (400, 10, 16) 1474560 primarycap_squash[0][0]


input_2 (InputLayer) [(None, 10)] 0


mask (Mask) (400, 160) 0 digitcaps[0][0]
input_2[0][0]


capsnet (Length) (400, 10) 0 digitcaps[0][0]


decoder (Sequential) (None, 28, 28, 1) 1411344 mask[0][0]

Total params: 8,215,568
Trainable params: 8,215,568
Non-trainable params: 0


end!
------------------------------Begin: manipulate------------------------------
2020-12-20 05:58:34.387299: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll
2020-12-20 05:58:34.628204: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll
2020-12-20 05:58:35.453403: W tensorflow/stream_executor/gpu/redzone_allocator.cc:314] Internal: Invoking GPU asm compilation is supported on Cuda non-Windows platforms only
Relying on driver to perform ptx compilation.
Modify $PATH to customize ptxas location.
This message will be only logged once.
Traceback (most recent call last):
File "C:/CapsNet-Keras-tf2.2/capsulenet.py", line 273, in
manipulate_latent(manipulate_model, (x_test, y_test), args)
File "C:/python/CapsNet-Keras-tf2.2/capsulenet.py", line 184, in manipulate_latent
x_recon = model.predict([x, y, tmp])
File "N:\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 130, in _method_wrapper
return method(self, *args, **kwargs)
File "N:\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1599, in predict
tmp_batch_outputs = predict_function(iterator)
File "N:\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py", line 780, in call
result = self._call(*args, **kwds)
File "N:\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py", line 846, in _call
return self._concrete_stateful_fn._filtered_call(canon_args, canon_kwds) # pylint: disable=protected-access
File "N:\anaconda3\lib\site-packages\tensorflow\python\eager\function.py", line 1848, in _filtered_call
cancellation_manager=cancellation_manager)
File "N:\anaconda3\lib\site-packages\tensorflow\python\eager\function.py", line 1924, in _call_flat
ctx, args, cancellation_manager=cancellation_manager))
File "N:\anaconda3\lib\site-packages\tensorflow\python\eager\function.py", line 550, in call
ctx=ctx)
File "N:\anaconda3\lib\site-packages\tensorflow\python\eager\execute.py", line 60, in quick_execute
inputs, attrs, num_outputs)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 9216 values, but the requested shape requires a multiple of 3200
[[node functional_5/primarycap_reshape/Reshape (defined at C:/CapsNet-Keras-tf2.2/capsulenet.py:184) ]] [Op:__inference_predict_function_992]

Function call stack:
predict_function

How to fix this issue?

@ghost
Copy link

ghost commented Jan 16, 2021

I had the same error.
How about making the batch_size on line 180 of capsule.py explicit, like in the test function?

x_recon = model.predict([x, y, tmp], batch_size=1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant