Tensorflow “如何导出”教程中保存的模型;“用于图纸分类的递归神经网络”;

Tensorflow “如何导出”教程中保存的模型;“用于图纸分类的递归神经网络”;,tensorflow,tensorflow-serving,Tensorflow,Tensorflow Serving,我正在阅读tensorflow的教程,在如何保存经过训练的模型方面遇到了一个问题 在本教程中,定义并训练了一个递归神经网络来进行图形分类。这是相应的代码: estimator = tf.estimator.Estimator( model_fn=model_fn, model_dir=output_dir, config=config, params=model_params) # Train the model. tf.contrib.l

我正在阅读tensorflow的教程,在如何保存经过训练的模型方面遇到了一个问题

在本教程中,定义并训练了一个递归神经网络来进行图形分类。这是相应的代码:

estimator = tf.estimator.Estimator(
      model_fn=model_fn,
      model_dir=output_dir,
      config=config,
      params=model_params)
  # Train the model.
  tf.contrib.learn.Experiment(
      estimator=estimator,
      train_input_fn=get_input_fn(
          mode=tf.contrib.learn.ModeKeys.TRAIN,
          tfrecord_pattern=FLAGS.training_data,
          batch_size=FLAGS.batch_size),
      train_steps=FLAGS.steps,
      eval_input_fn=get_input_fn(
          mode=tf.contrib.learn.ModeKeys.EVAL,
          tfrecord_pattern=FLAGS.eval_data,
          batch_size=FLAGS.batch_size),
      min_eval_frequency=1000)

没有给出显示如何导出和保存模型的代码。我该怎么做

本教程使用了
估计器
API。训练模型后,可以通过调用
export\u savedmodel()
方法保存模型:

export_dir = './' # path to store the model
estimator.export_savedmodel(export_dir, serving_input_fn)
service_input_fn
是训练时间内与
input_fn
相当的服务时间。此函数应返回一个
ServingInputReceiver
对象。该对象的目标是接收服务请求,对其进行解析,并将其发送到模型进行推理。要进行解析,需要提供一个
feature\u spec
字典,告诉解析函数需要哪些特性。从文档中:

feature_spec = {'foo': tf.FixedLenFeature(...),
                'bar': tf.VarLenFeature(...)}
有关如何从头开始构建它的详细说明,请参见

在大多数情况下,您可以使用
build\u parsing\u serving\u input\u receiver\u fn
build\u raw\u serving\u input\u receiver\u fn
实用程序函数来构建
serving\u input\u fn
。解析接收器需要如上所示的功能规范,原始接收器需要从字符串到张量的映射,并允许您将“原始”(未序列化)输入数据作为请求传递给模型。例如:

serving_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(
feature_spec,
default_batch_size=None)