Closed zgbkdlm closed 7 years ago
Hi, I also faced similar problem. I referred to this, I guess, If we only save the weights, then model architecture need always need to be known or documented properly. So, I wanted to save the model with lambda function in Keras.
I tried two approaches:
Approach-1: I did not try to change the vgg_mean function
vgg_mean = np.array([123.68, 116.779, 103.939]).reshape((3,1,1))
def vgg_preprocess(x):
x = x - vgg_mean # subtract mean
return x[:, ::-1] # reverse axis bgr->rgb '
And, then I was able to save the model. But, when I reload the saved model
new_model = load_model('my_model_copy2.h5',custom_objects={'vgg_mean': vgg_mean})
I get error mentioning 'global name vgg_mean is not defined". Gist file for this working is located here.
Approach 2:
I referred to this: and changed vgg_preprocess function as below:
def vgg_preprocess(x, vgg_mean):
x = x - vgg_mean # subtract mean
return x[:, ::-1]
I get below error, when I try to save the model:
ValueError: can only convert an array of size 1 to a Python scalar Gist file for this working is here.
How to save the model both architecture and weights with lambda function?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.
I was saving the encoder of the example : "examples/variational_autoencoder.py"
But when I load it, the error ocurrs,
batch_size
not defined. It doesn't work even I set a global batch_size.