Stack Exchange
Save and load keras autoencoder
Look at this strange load/save model situation. I saved variational autoencoder model and its encoder and decoder:
autoencoder.save("autoencoder_save", overwrite=True)
encoder.save("encoder_save", overwrite=True)
decoder.save("decoder_save", overwrite=T)

After that I loaded all of it from the disk:
autoencoder_disk = load_model("autoencoder_save", custom_objects={'KLDivergenceLayer': KLDivergenceLayer,
                                                       'nll': nll})
encoder_disk = load_model("encoder_save", custom_objects={'KLDivergenceLayer': KLDivergenceLayer,
                                                       'nll': nll})
decoder_disk = load_model("decoder_save", custom_objects={'KLDivergenceLayer': KLDivergenceLayer,
                                                       'nll': nll})

If I try 
x_test_encoded = encoder_disk.predict(x_test,batch_size=batch_size)
x_test_decoded = decoder_disk.predict(x_test_encoded)
print(np.round(x_test_decoded[3]))

Everything works just fine as if I use encoder/decoder from the memory, but if I try
vae = autoencoder_disk.predict(x_test_encoded) 

I got
ValueError: Error when checking model : 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:...

although I can predict from the variational autoencoder from the memory. Why autoencoder does not work when it is loaded from the disk?

It would be helpful to provide reproducible code to understand how your models are defined. My guess is that vae = autoencoder_disk.predict(x_test_encoded)  should be vae = autoencoder_disk.predict(x_test), since x_test_encoded seems to be the encoder's output.

Yes, you are right. It should be as you wrote. The models are defined just like in here: http://tiao.io/listings/vae/variational_autoencoder.py.html

acc to line 72 of your code, vae needs a list with 2 input. You are only providing 1 input. Hence you are seeing the error.

I tried to put eps in custom:_objects like all other variables:
custom_objects={'KLDivergenceLayer': KLDivergenceLayer, 'nll': nll, 'latent_dim': latent_dim, 'epsilon_std',                                       'eps':eps,'z':z
Unfortunately without success.
I also correct vae.predict() line to vae.predict(x_test)

THe point is that it works when I have the model in memory and it is not working when I load it.

You are passing the encoded output x_test_encoded as the input to the autoencoder autoencoder_disk.predict(x_test_encoded). You should pass the original input the encoder expects x_test instead. 

I'm so sorry because of misunderstanding. I mean that I wrote wrong in a question, not in my code.

The answer is in variables according to the link https://stackoverflow.com/questions/41754247/keras-save-model-issue?
Unfortunately I cannot find missed variable(s).
