Keras:将模型保存为适用于Google Cloud ML Engine的适当格式(缺少功能)

时间:2018-10-04 00:50:55

标签: python tensorflow keras

我正在尝试在Google Cloud ML Engine上部署最近受过训练的Keras模型。我四处搜索以查看所保存的模型对于ML Engine所需的格式,并发现了以下内容:

\

但是,在Keras 2.1.3中,import keras.backend as K import tensorflow as tf 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 = tf.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 = 'YOUR_EXPORT_PATH' + '/export' builder = saved_model_builder.SavedModelBuilder(export_path) signature = predict_signature_def(inputs={'NAME_YOUR_INPUT': new_Model.input}, outputs={'NAME_YOUR_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() 似乎不再具有keras.backendclear_session(), set_session()。解决这个问题的现代方法是什么?这些功能现在存在于其他地方吗?

谢谢!

0 个答案:

没有答案