XifengGuo / CapsNet-Keras

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

model.predict() on exported model #109

Open GaganaB opened 4 years ago

GaganaB commented 4 years ago

Hi,

As I explained in this issue here: https://github.com/XifengGuo/CapsNet-Keras/issues/95 I was able to resolve exporting the model and trained weights.

test_dicoms = ['test1.png','test2.png','test3.png','test4.png','test5.png','test6.png']
for img in test_dicoms: 
        full_size_image = io.imread(img, as_gray=True)
        model.predict(np.asarray(full_size_image))

throws the following error: ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead got the following list of 1 arrays: [array([[115, 164, 173, 170, 174, 167, 148, 125, 124, 126, 150, 191, 198, 206, 205, 209, 191, 180, 128, 109, 99, 67, 63, 58, 50, 41, 32, 41], [150, 173, 191, 188, 191, 1...

Any help is appreciated. Thanks.

Note: test_dicoms has the correct path and images are already 28 * 28 (verified with image.shape).

XifengGuo commented 4 years ago

@GaganaB Did you use the model or eval_model? https://github.com/XifengGuo/CapsNet-Keras/blob/2f6d47dd205c7d77fc3d43626feee4c45d3c6db4/capsulenet.py#L242-L244

If you use model, which is 2-in-2-out model, you should feed a tuple with 2 arrays, like outputs = model.predict(x, y). https://github.com/XifengGuo/CapsNet-Keras/blob/2f6d47dd205c7d77fc3d43626feee4c45d3c6db4/capsulenet.py#L69

If you use eval_model, which is a 1-in-2-out model, you should feed an array, like outputs = model.predict(x) https://github.com/XifengGuo/CapsNet-Keras/blob/2f6d47dd205c7d77fc3d43626feee4c45d3c6db4/capsulenet.py#L70