GC ML Engine outputs the same result with two different models












0















I have developed two different versions of a model in Keras and converted them to Tensorflow like this:



import keras.backend as K
from keras.models import load_model, Sequential
from tensorflow.python.saved_model import builder as saved_model_builder
from tensorflow.python.saved_model import tag_constants, signature_constants
from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def

# reset session
K.clear_session()
sess = tensorflow.Session()
K.set_session(sess)

# disable loading of learning nodes
K.set_learning_phase(0)

# load model
model = load_model('model.h5')
config = model.get_config()
weights = model.get_weights()
new_Model = Sequential.from_config(config)
new_Model.set_weights(weights)

# export saved model
export_path = 'export-pb-variables'

builder = saved_model_builder.SavedModelBuilder(export_path) #builder = tf.saved_model.builder.SavedModelBuilder(export_path)


signature = predict_signature_def(inputs={'input': new_Model.input},
outputs={'output': new_Model.output})

with K.get_session() as sess:
builder.add_meta_graph_and_variables(
sess=sess,
tags=[tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature}
)
builder.save()


Each model resulted in .pb file together with variables folder. I have then tested that I can use these files to restore the model and get predictions in this way:



# reset session
keras.backend.clear_session()
sess = tf.Session()
keras.backend.set_session(sess)

with keras.backend.get_session() as sess:
tf.saved_model.loader.load(sess, [tag_constants.SERVING], path_to_exported_model)
result = sess.run('dense_1/Sigmoid:0', feed_dict={'lstm1_input_1:0': one_input_example})
print(result)


Locally the two versions are reproducible and give me different results for different input parameters, as it should be. However, after I upload them to GC to make predictions using ML Engine, these two versions produce the same result (which differs significantly from the results of either of two versions locally). If I test other input examples, the results are again the same (but not exactly the same among different inputs)



Can you advise what can be a possible reason for this.










share|improve this question

























  • My naive guess is that I'm not exporting the model correctly.

    – Daria
    Nov 26 '18 at 8:58
















0















I have developed two different versions of a model in Keras and converted them to Tensorflow like this:



import keras.backend as K
from keras.models import load_model, Sequential
from tensorflow.python.saved_model import builder as saved_model_builder
from tensorflow.python.saved_model import tag_constants, signature_constants
from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def

# reset session
K.clear_session()
sess = tensorflow.Session()
K.set_session(sess)

# disable loading of learning nodes
K.set_learning_phase(0)

# load model
model = load_model('model.h5')
config = model.get_config()
weights = model.get_weights()
new_Model = Sequential.from_config(config)
new_Model.set_weights(weights)

# export saved model
export_path = 'export-pb-variables'

builder = saved_model_builder.SavedModelBuilder(export_path) #builder = tf.saved_model.builder.SavedModelBuilder(export_path)


signature = predict_signature_def(inputs={'input': new_Model.input},
outputs={'output': new_Model.output})

with K.get_session() as sess:
builder.add_meta_graph_and_variables(
sess=sess,
tags=[tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature}
)
builder.save()


Each model resulted in .pb file together with variables folder. I have then tested that I can use these files to restore the model and get predictions in this way:



# reset session
keras.backend.clear_session()
sess = tf.Session()
keras.backend.set_session(sess)

with keras.backend.get_session() as sess:
tf.saved_model.loader.load(sess, [tag_constants.SERVING], path_to_exported_model)
result = sess.run('dense_1/Sigmoid:0', feed_dict={'lstm1_input_1:0': one_input_example})
print(result)


Locally the two versions are reproducible and give me different results for different input parameters, as it should be. However, after I upload them to GC to make predictions using ML Engine, these two versions produce the same result (which differs significantly from the results of either of two versions locally). If I test other input examples, the results are again the same (but not exactly the same among different inputs)



Can you advise what can be a possible reason for this.










share|improve this question

























  • My naive guess is that I'm not exporting the model correctly.

    – Daria
    Nov 26 '18 at 8:58














0












0








0








I have developed two different versions of a model in Keras and converted them to Tensorflow like this:



import keras.backend as K
from keras.models import load_model, Sequential
from tensorflow.python.saved_model import builder as saved_model_builder
from tensorflow.python.saved_model import tag_constants, signature_constants
from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def

# reset session
K.clear_session()
sess = tensorflow.Session()
K.set_session(sess)

# disable loading of learning nodes
K.set_learning_phase(0)

# load model
model = load_model('model.h5')
config = model.get_config()
weights = model.get_weights()
new_Model = Sequential.from_config(config)
new_Model.set_weights(weights)

# export saved model
export_path = 'export-pb-variables'

builder = saved_model_builder.SavedModelBuilder(export_path) #builder = tf.saved_model.builder.SavedModelBuilder(export_path)


signature = predict_signature_def(inputs={'input': new_Model.input},
outputs={'output': new_Model.output})

with K.get_session() as sess:
builder.add_meta_graph_and_variables(
sess=sess,
tags=[tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature}
)
builder.save()


Each model resulted in .pb file together with variables folder. I have then tested that I can use these files to restore the model and get predictions in this way:



# reset session
keras.backend.clear_session()
sess = tf.Session()
keras.backend.set_session(sess)

with keras.backend.get_session() as sess:
tf.saved_model.loader.load(sess, [tag_constants.SERVING], path_to_exported_model)
result = sess.run('dense_1/Sigmoid:0', feed_dict={'lstm1_input_1:0': one_input_example})
print(result)


Locally the two versions are reproducible and give me different results for different input parameters, as it should be. However, after I upload them to GC to make predictions using ML Engine, these two versions produce the same result (which differs significantly from the results of either of two versions locally). If I test other input examples, the results are again the same (but not exactly the same among different inputs)



Can you advise what can be a possible reason for this.










share|improve this question
















I have developed two different versions of a model in Keras and converted them to Tensorflow like this:



import keras.backend as K
from keras.models import load_model, Sequential
from tensorflow.python.saved_model import builder as saved_model_builder
from tensorflow.python.saved_model import tag_constants, signature_constants
from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def

# reset session
K.clear_session()
sess = tensorflow.Session()
K.set_session(sess)

# disable loading of learning nodes
K.set_learning_phase(0)

# load model
model = load_model('model.h5')
config = model.get_config()
weights = model.get_weights()
new_Model = Sequential.from_config(config)
new_Model.set_weights(weights)

# export saved model
export_path = 'export-pb-variables'

builder = saved_model_builder.SavedModelBuilder(export_path) #builder = tf.saved_model.builder.SavedModelBuilder(export_path)


signature = predict_signature_def(inputs={'input': new_Model.input},
outputs={'output': new_Model.output})

with K.get_session() as sess:
builder.add_meta_graph_and_variables(
sess=sess,
tags=[tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature}
)
builder.save()


Each model resulted in .pb file together with variables folder. I have then tested that I can use these files to restore the model and get predictions in this way:



# reset session
keras.backend.clear_session()
sess = tf.Session()
keras.backend.set_session(sess)

with keras.backend.get_session() as sess:
tf.saved_model.loader.load(sess, [tag_constants.SERVING], path_to_exported_model)
result = sess.run('dense_1/Sigmoid:0', feed_dict={'lstm1_input_1:0': one_input_example})
print(result)


Locally the two versions are reproducible and give me different results for different input parameters, as it should be. However, after I upload them to GC to make predictions using ML Engine, these two versions produce the same result (which differs significantly from the results of either of two versions locally). If I test other input examples, the results are again the same (but not exactly the same among different inputs)



Can you advise what can be a possible reason for this.







tensorflow keras google-cloud-ml






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 15:22







Daria

















asked Nov 23 '18 at 13:49









DariaDaria

184




184













  • My naive guess is that I'm not exporting the model correctly.

    – Daria
    Nov 26 '18 at 8:58



















  • My naive guess is that I'm not exporting the model correctly.

    – Daria
    Nov 26 '18 at 8:58

















My naive guess is that I'm not exporting the model correctly.

– Daria
Nov 26 '18 at 8:58





My naive guess is that I'm not exporting the model correctly.

– Daria
Nov 26 '18 at 8:58












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447932%2fgc-ml-engine-outputs-the-same-result-with-two-different-models%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447932%2fgc-ml-engine-outputs-the-same-result-with-two-different-models%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen