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


Python spec_builder.complete_master_spec方法代码示例

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


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

示例1: load_model

# 需要导入模块: from dragnn.python import spec_builder [as 别名]
# 或者: from dragnn.python.spec_builder import complete_master_spec [as 别名]
def load_model(base_dir, master_spec_name, checkpoint_name):
    """
    Function to load the syntaxnet models. Highly specific to the tutorial
    format right now.
    """
    # Read the master spec
    master_spec = spec_pb2.MasterSpec()
    with open(os.path.join(base_dir, master_spec_name), "r") as f:
        text_format.Merge(f.read(), master_spec)
    spec_builder.complete_master_spec(master_spec, None, base_dir)
    logging.set_verbosity(logging.WARN)  # Turn off TensorFlow spam.

    # Initialize a graph
    graph = tf.Graph()
    with graph.as_default():
        hyperparam_config = spec_pb2.GridPoint()
        builder = graph_builder.MasterBuilder(master_spec, hyperparam_config)
        # This is the component that will annotate test sentences.
        annotator = builder.add_annotation(enable_tracing=True)
        builder.add_saver()  # "Savers" can save and load models; here, we're only going to load.

    sess = tf.Session(graph=graph)
    with graph.as_default():
        #sess.run(tf.global_variables_initializer())
        #sess.run('save/restore_all', {'save/Const:0': os.path.join(base_dir, checkpoint_name)})
        builder.saver.restore(sess, os.path.join(base_dir, checkpoint_name))

    def annotate_sentence(sentence):
        with graph.as_default():
            return sess.run([annotator['annotations'], annotator['traces']],
                            feed_dict={annotator['input_batch']: [sentence]})
    return annotate_sentence 
开发者ID:hltcoe,项目名称:PredPatt,代码行数:34,代码来源:ParseyPredFace.py

示例2: load_model

# 需要导入模块: from dragnn.python import spec_builder [as 别名]
# 或者: from dragnn.python.spec_builder import complete_master_spec [as 别名]
def load_model(self,base_dir, master_spec_name, checkpoint_name):
        # Read the master spec
        master_spec = spec_pb2.MasterSpec()
        with open(os.path.join(base_dir, master_spec_name), "r") as f:
            text_format.Merge(f.read(), master_spec)
        spec_builder.complete_master_spec(master_spec, None, base_dir)
        logging.set_verbosity(logging.WARN)  # Turn off TensorFlow spam.

        # Initialize a graph
        graph = tf.Graph()
        with graph.as_default():
            hyperparam_config = spec_pb2.GridPoint()
            builder = graph_builder.MasterBuilder(master_spec, hyperparam_config)
            # This is the component that will annotate test sentences.
            annotator = builder.add_annotation(enable_tracing=True)
            builder.add_saver()  # "Savers" can save and load models; here, we're only going to load.

        sess = tf.Session(graph=graph)
        with graph.as_default():
            # sess.run(tf.global_variables_initializer())
            # sess.run('save/restore_all', {'save/Const:0': os.path.join(base_dir, checkpoint_name)})
            builder.saver.restore(sess, os.path.join(base_dir, checkpoint_name))

        def annotate_sentence(sentence):
            with graph.as_default():
                return sess.run([annotator['annotations'], annotator['traces']],
                                feed_dict={annotator['input_batch']: [sentence]})

        return annotate_sentence 
开发者ID:ljm625,项目名称:syntaxnet-rest-api,代码行数:31,代码来源:dragnn_parser.py

示例3: export

# 需要导入模块: from dragnn.python import spec_builder [as 别名]
# 或者: from dragnn.python.spec_builder import complete_master_spec [as 别名]
def export(master_spec_path, params_path, resource_path, export_path,
           export_moving_averages):
  """Restores a model and exports it in SavedModel form.

  This method loads a graph specified by the spec at master_spec_path and the
  params in params_path. It then saves the model in SavedModel format to the
  location specified in export_path.

  Args:
    master_spec_path: Path to a proto-text master spec.
    params_path: Path to the parameters file to export.
    resource_path: Path to resources in the master spec.
    export_path: Path to export the SavedModel to.
    export_moving_averages: Whether to export the moving average parameters.
  """
  # Old CoNLL checkpoints did not need a known-word-map. Create a temporary if
  # that file is missing.
  if not tf.gfile.Exists(os.path.join(resource_path, 'known-word-map')):
    with tf.gfile.FastGFile(os.path.join(resource_path, 'known-word-map'),
                            'w') as out_file:
      out_file.write('This file intentionally left blank.')

  graph = tf.Graph()
  master_spec = spec_pb2.MasterSpec()
  with tf.gfile.FastGFile(master_spec_path) as fin:
    text_format.Parse(fin.read(), master_spec)

  # This is a workaround for an issue where the segmenter master-spec had a
  # spurious resource in it; this resource was not respected in the spec-builder
  # and ended up crashing the saver (since it didn't really exist).
  for component in master_spec.component:
    del component.resource[:]

  spec_builder.complete_master_spec(master_spec, None, resource_path)

  # Remove '/' if it exists at the end of the export path, ensuring that
  # path utils work correctly.
  stripped_path = export_path.rstrip('/')
  saver_lib.clean_output_paths(stripped_path)

  short_to_original = saver_lib.shorten_resource_paths(master_spec)
  saver_lib.export_master_spec(master_spec, graph)
  saver_lib.export_to_graph(master_spec, params_path, stripped_path, graph,
                            export_moving_averages)
  saver_lib.export_assets(master_spec, short_to_original, stripped_path) 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:47,代码来源:conll_checkpoint_converter.py


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