本文整理匯總了Python中tensorflow.python.saved_model.signature_def_utils_impl.predict_signature_def方法的典型用法代碼示例。如果您正苦於以下問題:Python signature_def_utils_impl.predict_signature_def方法的具體用法?Python signature_def_utils_impl.predict_signature_def怎麽用?Python signature_def_utils_impl.predict_signature_def使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.saved_model.signature_def_utils_impl
的用法示例。
在下文中一共展示了signature_def_utils_impl.predict_signature_def方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _store_tf
# 需要導入模塊: from tensorflow.python.saved_model import signature_def_utils_impl [as 別名]
# 或者: from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def [as 別名]
def _store_tf(self, name, session):
json_model_file = open(os.path.join(self.model_path, name + '.json'), "r").read()
loaded_model = model_from_json(json_model_file)
loaded_model.load_weights(os.path.join(self.model_path, name + '.h5'))
builder = saved_model_builder.SavedModelBuilder(os.path.join(self.model_path, 'tf.txt'))
signature = predict_signature_def(inputs={'states': loaded_model.input},
outputs={'price': loaded_model.output})
builder.add_meta_graph_and_variables(sess=session,
tags=[tag_constants.SERVING],
signature_def_map={'helpers': signature})
builder.save()
_logger.info("Saved tf.txt model to disk")
示例2: saveWithSavedModel
# 需要導入模塊: from tensorflow.python.saved_model import signature_def_utils_impl [as 別名]
# 或者: from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def [as 別名]
def saveWithSavedModel():
# K.set_learning_phase(0) # all new operations will be in test mode from now on
# wordIndex = loadWordIndex()
model = createModel()
model.load_weights(KERAS_WEIGHTS_FILE)
export_path = os.path.join(PUNCTUATOR_DIR, 'graph') # where to save the exported graph
shutil.rmtree(export_path, True)
export_version = 1 # version number (integer)
import tensorflow as tf
sess = tf.Session()
saver = tf.train.Saver(sharded=True)
from tensorflow.contrib.session_bundle import exporter
model_exporter = exporter.Exporter(saver)
signature = exporter.classification_signature(input_tensor=model.input,scores_tensor=model.output)
# model_exporter.init(sess.graph.as_graph_def(),default_graph_signature=signature)
tf.initialize_all_variables().run(session=sess)
# model_exporter.export(export_path, tf.constant(export_version), sess)
from tensorflow.python.saved_model import builder as saved_model_builder
builder = saved_model_builder.SavedModelBuilder(export_path)
from tensorflow.python.saved_model import signature_constants
from tensorflow.python.saved_model import tag_constants
legacy_init_op = tf.group(tf.tables_initializer(), name='legacy_init_op')
from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def
signature_def = predict_signature_def(
{signature_constants.PREDICT_INPUTS: model.input},
{signature_constants.PREDICT_OUTPUTS: model.output})
builder.add_meta_graph_and_variables(
sess, [tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
signature_def
},
legacy_init_op=legacy_init_op)
builder.save()
示例3: main
# 需要導入模塊: from tensorflow.python.saved_model import signature_def_utils_impl [as 別名]
# 或者: from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def [as 別名]
def main():
args = _parse_args()
trained_checkpoint_prefix = tf.train.latest_checkpoint(args.model_dir)
# Each model folder must be named '0', '1', ...
export_dir = os.path.join(args.model_dir, 'models', '0')
shutil.rmtree(export_dir, ignore_errors=True)
with tf.compat.v1.Session(
graph=tf.Graph(),
config=tf.compat.v1.ConfigProto(allow_soft_placement=True)) as sess:
# Restore from checkpoint
loader = tf.compat.v1.train.import_meta_graph(
trained_checkpoint_prefix + '.meta')
loader.restore(sess, trained_checkpoint_prefix)
# Export checkpoint to SavedModel
builder = tf.compat.v1.saved_model.builder.SavedModelBuilder(export_dir)
images = sess.graph.get_tensor_by_name('inputs/split_images:0')
is_training = sess.graph.get_tensor_by_name('inputs/is_training:0')
predictions = sess.graph.get_tensor_by_name('predictions:0')
signature = predict_signature_def(
inputs={'images': images, 'is_training': is_training},
outputs={'predictions': predictions})
builder.add_meta_graph_and_variables(
sess,
[tf.saved_model.SERVING],
strip_default_attrs=True,
signature_def_map={'predict': signature})
builder.save()