当前位置: 首页>>代码示例>>Python>>正文


Python exporter.Exporter方法代码示例

本文整理汇总了Python中tensorflow.contrib.session_bundle.exporter.Exporter方法的典型用法代码示例。如果您正苦于以下问题:Python exporter.Exporter方法的具体用法?Python exporter.Exporter怎么用?Python exporter.Exporter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.contrib.session_bundle.exporter的用法示例。


在下文中一共展示了exporter.Exporter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _export_graph

# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import Exporter [as 别名]
def _export_graph(graph, saver, checkpoint_path, export_dir,
                  default_graph_signature, named_graph_signatures,
                  exports_to_keep):
  """Exports graph via session_bundle, by creating a Session."""
  with graph.as_default():
    with tf_session.Session('') as session:
      variables.local_variables_initializer()
      lookup_ops.tables_initializer()
      saver.restore(session, checkpoint_path)

      export = exporter.Exporter(saver)
      export.init(
          init_op=control_flow_ops.group(
              variables.local_variables_initializer(),
              lookup_ops.tables_initializer()),
          default_graph_signature=default_graph_signature,
          named_graph_signatures=named_graph_signatures,
          assets_collection=ops.get_collection(ops.GraphKeys.ASSET_FILEPATHS))
      return export.export(export_dir, contrib_variables.get_global_step(),
                           session, exports_to_keep=exports_to_keep) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:export.py

示例2: _export_graph

# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import Exporter [as 别名]
def _export_graph(graph, saver, checkpoint_path, export_dir,
                  default_graph_signature, named_graph_signatures,
                  exports_to_keep):
  """Exports graph via session_bundle, by creating a Session."""
  with graph.as_default():
    with tf_session.Session('') as session:
      variables.local_variables_initializer()
      data_flow_ops.tables_initializer()
      saver.restore(session, checkpoint_path)

      export = exporter.Exporter(saver)
      export.init(init_op=control_flow_ops.group(
          variables.local_variables_initializer(),
          data_flow_ops.tables_initializer()),
                  default_graph_signature=default_graph_signature,
                  named_graph_signatures=named_graph_signatures,
                  assets_collection=ops.get_collection(
                      ops.GraphKeys.ASSET_FILEPATHS))
      return export.export(export_dir, contrib_variables.get_global_step(),
                           session, exports_to_keep=exports_to_keep) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:22,代码来源:export.py

示例3: _export_graph

# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import Exporter [as 别名]
def _export_graph(graph, saver, checkpoint_path, export_dir,
                  default_graph_signature, named_graph_signatures,
                  exports_to_keep):
  """Exports graph via session_bundle, by creating a Session."""
  with graph.as_default():
    with tf_session.Session('') as session:
      variables.local_variables_initializer()
      data_flow_ops.initialize_all_tables()
      saver.restore(session, checkpoint_path)

      export = exporter.Exporter(saver)
      export.init(init_op=control_flow_ops.group(
          variables.local_variables_initializer(),
          data_flow_ops.initialize_all_tables()),
                  default_graph_signature=default_graph_signature,
                  named_graph_signatures=named_graph_signatures,
                  assets_collection=ops.get_collection(
                      ops.GraphKeys.ASSET_FILEPATHS))
      return export.export(export_dir, contrib_variables.get_global_step(),
                           session, exports_to_keep=exports_to_keep) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:22,代码来源:export.py

示例4: Export

# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import Exporter [as 别名]
def Export():
  export_path = "/tmp/half_plus_two"
  with tf.Session() as sess:
    # Make model parameters a&b variables instead of constants to
    # exercise the variable reloading mechanisms.
    a = tf.Variable(0.5)
    b = tf.Variable(2.0)

    # Calculate, y = a*x + b
    # here we use a placeholder 'x' which is fed at inference time.
    x = tf.placeholder(tf.float32)
    y = tf.add(tf.multiply(a, x), b)

    # Run an export.
    tf.global_variables_initializer().run()
    export = exporter.Exporter(tf.train.Saver())
    export.init(named_graph_signatures={
        "inputs": exporter.generic_signature({"x": x}),
        "outputs": exporter.generic_signature({"y": y}),
        "regress": exporter.regression_signature(x, y)
    })
    export.export(export_path, tf.constant(123), sess) 
开发者ID:helmut-hoffer-von-ankershoffen,项目名称:jetson,代码行数:24,代码来源:export_half_plus_two.py

示例5: export_session_bundle

# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import Exporter [as 别名]
def export_session_bundle(self):
        export_dir_base = self.saver_spec.get('export_directory')
        if not export_dir_base:
            print("export_directory is None")

        checkpoint = tf.train.latest_checkpoint(self.saver_directory)
        if not checkpoint:
            raise NotFittedError("Couldn't find trained model at %s." % self.saver_directory)

        export_dir = saved_model_export_utils.get_timestamped_export_dir(export_dir_base)

        if self.distributed_spec:
            sess = tf.Session(target=self.server.target, graph=self.graph, config=self.session_config)
        else:
            sess = tf.Session(graph=self.graph)
        self.scaffold.saver.restore(sess, checkpoint)

        signature = {name: ts for name, ts in self.states_input.items()}
        signature["deterministic"] = self.deterministic_input
        signature["update"] = self.update_input

        exporter = Exporter(self.scaffold.saver)
        exporter.init(self.graph.as_graph_def(),
                      clear_devices=True,
                      default_graph_signature=generic_signature(signature))
        exporter.export(export_dir_base=export_dir,
                        global_step_tensor=self.timestep,
                        sess=sess)

        return export_dir 
开发者ID:rec-agent,项目名称:rec-rl,代码行数:32,代码来源:model.py

示例6: saveWithSavedModel

# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import Exporter [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() 
开发者ID:vackosar,项目名称:keras-punctuator,代码行数:42,代码来源:punctuator.py

示例7: export_model

# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import Exporter [as 别名]
def export_model(sess, inputs_signature, outputs_signature):
  # Export the model for generic inference service
  print("Exporting trained model to {}".format(FLAGS.model_path))
  saver = tf.train.Saver(sharded=True)
  model_exporter = exporter.Exporter(saver)
  model_exporter.init(
      sess.graph.as_graph_def(),
      named_graph_signatures={
          "inputs": exporter.generic_signature(inputs_signature),
          "outputs": exporter.generic_signature(outputs_signature)
      })
  model_exporter.export(FLAGS.model_path, tf.constant(FLAGS.model_version),
                        sess)
  print("Done exporting!") 
开发者ID:XiaoMi,项目名称:cloud-ml-sdk,代码行数:16,代码来源:task.py

示例8: main

# 需要导入模块: from tensorflow.contrib.session_bundle import exporter [as 别名]
# 或者: from tensorflow.contrib.session_bundle.exporter import Exporter [as 别名]
def main():
  # Define training data
  x = np.ones(FLAGS.batch_size)
  y = np.ones(FLAGS.batch_size)

  # Define the model
  X = tf.placeholder(tf.float32, shape=[None])
  Y = tf.placeholder(tf.float32, shape=[None])
  w = tf.Variable(1.0, name="weight")
  b = tf.Variable(1.0, name="bias")
  loss = tf.square(Y - tf.mul(X, w) - b)
  train_op = tf.train.GradientDescentOptimizer(0.01).minimize(loss)
  predict_op  = tf.mul(X, w) + b

  saver = tf.train.Saver()
  checkpoint_dir = FLAGS.checkpoint_dir
  checkpoint_file = checkpoint_dir + "/checkpoint.ckpt"
  if not os.path.exists(checkpoint_dir):
    os.makedirs(checkpoint_dir)

  # Start the session
  with tf.Session() as sess:
    sess.run(tf.initialize_all_variables())

    ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
    if ckpt and ckpt.model_checkpoint_path:
      print("Continue training from the model {}".format(ckpt.model_checkpoint_path))
      saver.restore(sess, ckpt.model_checkpoint_path)

    # Start training
    start_time = time.time()
    for epoch in range(FLAGS.epoch_number):
      sess.run(train_op, feed_dict={X: x, Y: y})

      # Start validating
      if epoch % FLAGS.steps_to_validate == 0:
        end_time = time.time()
        print("[{}] Epoch: {}".format(end_time - start_time, epoch))

        saver.save(sess, checkpoint_file)
        start_time = end_time

    # Print model variables
    w_value, b_value = sess.run([w, b])
    print("The model of w: {}, b: {}".format(w_value, b_value))

    # Export the model
    print("Exporting trained model to {}".format(FLAGS.model_path))
    model_exporter = exporter.Exporter(saver)
    model_exporter.init(
      sess.graph.as_graph_def(),
      named_graph_signatures={
        'inputs': exporter.generic_signature({"features": X}),
        'outputs': exporter.generic_signature({"prediction": predict_op})
      })
    model_exporter.export(FLAGS.model_path, tf.constant(FLAGS.export_version), sess)
    print 'Done exporting!' 
开发者ID:tobegit3hub,项目名称:tensorflow_template_application,代码行数:59,代码来源:train.py


注:本文中的tensorflow.contrib.session_bundle.exporter.Exporter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。