XifengGuo / CapsNet-Keras

A Keras implementation of CapsNet in NIPS2017 paper "Dynamic Routing Between Capsules". Now test error = 0.34%.
MIT License
2.47k stars 651 forks source link

InvalidArgumentError: (using google colab) #113

Closed yogi1510 closed 4 years ago

yogi1510 commented 4 years ago

I got the following error while running the code in google colab with my local dataset. I have resized the dataset to 28x28. It has only two classes. I have even scaled them to [0,1]. Can you please take a look @XifengGuo .Thanks!

InvalidArgumentError: Specified a list with shape [2,1152,8,1] from a tensor with shape [2,1008,8,1] [[node model_9/digitcaps/map/TensorArrayUnstack/TensorListFromTensor (defined at /content/capsulelayers.py:135) ]] [Op:__inference_test_function_14555]

Errors may have originated from an input operation. Input Source operations connected to node model_9/digitcaps/map/TensorArrayUnstack/TensorListFromTensor: model_9/digitcaps/Tile (defined at /content/capsulelayers.py:127)

Function call stack: test_function

bklooste commented 4 years ago

What version of tensorflow ? Its quite picky .. I posted a link for a working collab for 2.2 https://github.com/bklooste/tensorflowcollab/blob/master/CapsuleNet_on_MNIST_with_retrain.ipynb it wasnt easy but im not super proficient in tf . I posted a previous issue because the code bakes the shape into model . This means you change the batch size or dont have samples exactly divisible by batch size then it dont work .

yogi1510 commented 4 years ago

Thank you so much! 🙏@bklooste. It really helped me. I stoped my research due to this error. Yeah, I am using tf2.2 version and the training set is divisible by batch size but the validation set is not. So,I added few images to the validation set and it worked fine!. Actually in the previous version it worked well even if the samples are not exactly divisible by batch size. So, I didn't taught about it. Thanks again : )

Ellyuca commented 4 years ago

@bklooste OMG. thanks so much for the notebook version. I was actually looking for something like that to test some things out. ♥♥♥