當前位置: 首頁>>代碼示例>>Python>>正文


Python spec_pb2.MasterSpec方法代碼示例

本文整理匯總了Python中dragnn.protos.spec_pb2.MasterSpec方法的典型用法代碼示例。如果您正苦於以下問題:Python spec_pb2.MasterSpec方法的具體用法?Python spec_pb2.MasterSpec怎麽用?Python spec_pb2.MasterSpec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dragnn.protos.spec_pb2的用法示例。


在下文中一共展示了spec_pb2.MasterSpec方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testRuntimeConcatentatedMatricesLinked

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def testRuntimeConcatentatedMatricesLinked(self):
    """Test generation of concatenated matrices."""
    # TODO(googleuser): Make MockComponent support runtime graph generation.
    master = MockMaster(build_runtime_graph=False)
    master.spec = spec_pb2.MasterSpec()
    text_format.Parse(self.test_spec_linked, master.spec)
    lstm_network_unit = self.construct_lstm_network_unit(master)
    with tf.variable_scope('bi_lstm', reuse=True):
      lstm_network_unit.create(
          self.fixed_word_embeddings(), [],
          self.get_context_tensor_arrays(lstm_network_unit), None, False)
      x_to_ico = lstm_network_unit.derived_params[0]()
      h_to_ico = lstm_network_unit.derived_params[1]()
      ico_bias = lstm_network_unit.derived_params[2]()

      # Should be the word dimension (32) to 3x the hidden dimension (128).
      self.assertEqual(x_to_ico.shape, (32, 384))

      # Should be the hidden dimension (128) to 3x the hidden dimension (128).
      self.assertEqual(h_to_ico.shape, (128, 384))

      # Should be equal to the hidden dimension (128) times 3.
      self.assertEqual(ico_bias.shape, (384,)) 
開發者ID:generalized-iou,項目名稱:g-tensorflow-models,代碼行數:25,代碼來源:network_units_test.py

示例2: __init__

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def __init__(self):
    self.spec = spec_pb2.MasterSpec()
    self.hyperparams = spec_pb2.GridPoint()
    self.lookup_component = {
        'previous': MockComponent(self, spec_pb2.ComponentSpec())
    } 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:8,代碼來源:network_units_test.py

示例3: setUp

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def setUp(self):
    # Clear the graph and all existing variables.  Otherwise, variables created
    # in different tests may collide with each other.
    tf.reset_default_graph()

    self._master = MockMaster()
    self._master.spec = spec_pb2.MasterSpec()

    # Add a component with a linked feature.
    component_spec = self._master.spec.component.add()
    component_spec.name = 'fake_linked'
    component_spec.backend.registered_name = 'FakeComponent'
    linked_feature = component_spec.linked_feature.add()
    linked_feature.source_component = 'fake_linked'
    linked_feature.source_translator = 'identity'
    linked_feature.embedding_dim = -1
    linked_feature.size = 2
    self._linked_component = MockComponent(self._master, component_spec)

    # Add a feature with a fixed feature.
    component_spec = self._master.spec.component.add()
    component_spec.name = 'fake_fixed'
    component_spec.backend.registered_name = 'FakeComponent'
    fixed_feature = component_spec.fixed_feature.add()
    fixed_feature.fml = 'input.word'
    fixed_feature.embedding_dim = 1
    fixed_feature.size = 1
    self._fixed_component = MockComponent(self._master, component_spec) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:30,代碼來源:network_units_test.py

示例4: _make_basic_master_spec

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def _make_basic_master_spec():
  """Constructs a simple spec.

  Modified version of nlp/saft/opensource/dragnn/tools/parser_trainer.py

  Returns:
    spec_pb2.MasterSpec instance.
  """
  # Construct the "lookahead" ComponentSpec. This is a simple right-to-left RNN
  # sequence model, which encodes the context to the right of each token. It has
  # no loss except for the downstream components.
  lookahead = spec_builder.ComponentSpecBuilder('lookahead')
  lookahead.set_network_unit(
      name='FeedForwardNetwork', hidden_layer_sizes='256')
  lookahead.set_transition_system(name='shift-only', left_to_right='true')
  lookahead.add_fixed_feature(name='words', fml='input.word', embedding_dim=64)
  lookahead.add_rnn_link(embedding_dim=-1)

  # Construct the ComponentSpec for parsing.
  parser = spec_builder.ComponentSpecBuilder('parser')
  parser.set_network_unit(name='FeedForwardNetwork', hidden_layer_sizes='256')
  parser.set_transition_system(name='arc-standard')
  parser.add_token_link(source=lookahead, fml='input.focus', embedding_dim=32)

  master_spec = spec_pb2.MasterSpec()
  master_spec.component.extend([lookahead.spec, parser.spec])
  return master_spec 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:29,代碼來源:render_spec_with_graphviz_test.py

示例5: LoadSpec

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def LoadSpec(self, spec_path):
    master_spec = spec_pb2.MasterSpec()
    testdata = os.path.join(FLAGS.test_srcdir,
                            'dragnn/core/testdata')
    with file(os.path.join(testdata, spec_path), 'r') as fin:
      text_format.Parse(fin.read().replace('TESTDATA', testdata), master_spec)
      return master_spec 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:9,代碼來源:graph_builder_test.py

示例6: master_spec_graph

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def master_spec_graph(master_spec):
  """Constructs a master spec graph.

  Args:
    master_spec: MasterSpec proto.

  Raises:
    TypeError, if master_spec is not the right type. N.B. that this may be
    raised if you import proto classes in non-standard ways (e.g. dynamically).

  Returns:
    SVG graph contents as a string.
  """
  if not isinstance(master_spec, spec_pb2.MasterSpec):
    raise TypeError("master_spec_graph() expects a MasterSpec input.")

  graph = pygraphviz.AGraph(directed=True)

  graph.node_attr.update(
      shape="box",
      style="filled",
      fillcolor="white",
      fontname="roboto, helvetica, arial",
      fontsize=11)
  graph.edge_attr.update(fontname="roboto, helvetica, arial", fontsize=11)

  for component in master_spec.component:
    graph.add_node(component.name, label=_component_contents(component))

  for component in master_spec.component:
    for linked_feature in component.linked_feature:
      graph.add_edge(
          linked_feature.source_component,
          component.name,
          label=_linked_feature_label(linked_feature))

  with warnings.catch_warnings():
    # Fontconfig spews some warnings, suppress them for now. (Especially because
    # they can clutter IPython notebooks).
    warnings.simplefilter("ignore")
    return graph.draw(format="svg", prog="dot") 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:43,代碼來源:render_spec_with_graphviz.py

示例7: _get_master_spec

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def _get_master_spec():
  return spec_pb2.MasterSpec(
      component=[spec_pb2.ComponentSpec(name='jalapeño')]) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:5,代碼來源:visualization_test.py

示例8: LoadSpec

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def LoadSpec(self, spec_path):
    master_spec = spec_pb2.MasterSpec()
    root_dir = os.path.join(FLAGS.test_srcdir,
                            'dragnn/python')
    with file(os.path.join(root_dir, 'testdata', spec_path), 'r') as fin:
      text_format.Parse(fin.read().replace('TOPDIR', root_dir), master_spec)
      return master_spec 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:9,代碼來源:dragnn_model_saver_lib_test.py

示例9: export

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def export(master_spec_path, params_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.
    export_path: Path to export the SavedModel to.
    export_moving_averages: Whether to export the moving average parameters.
  """

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

  # 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,代碼行數:32,代碼來源:dragnn_model_saver.py

示例10: __init__

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def __init__(self):
    self.spec = spec_pb2.MasterSpec()
    self.hyperparams = spec_pb2.GridPoint()
    self.lookup_component = {'mock': MockComponent()} 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:6,代碼來源:bulk_component_test.py

示例11: LoadSpec

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def LoadSpec(self, spec_path):
    master_spec = spec_pb2.MasterSpec()
    root_dir = os.path.join(FLAGS.test_srcdir,
                            'dragnn/python')
    with open(os.path.join(root_dir, 'testdata', spec_path), 'r') as fin:
      text_format.Parse(fin.read().replace('TOPDIR', root_dir), master_spec)
      return master_spec 
開發者ID:itsamitgoel,項目名稱:Gun-Detector,代碼行數:9,代碼來源:dragnn_model_saver_lib_test.py

示例12: LoadSpec

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [as 別名]
def LoadSpec(self, spec_path):
    master_spec = spec_pb2.MasterSpec()
    testdata = os.path.join(FLAGS.test_srcdir,
                            'dragnn/core/testdata')
    with open(os.path.join(testdata, spec_path), 'r') as fin:
      text_format.Parse(fin.read().replace('TESTDATA', testdata), master_spec)
      return master_spec 
開發者ID:itsamitgoel,項目名稱:Gun-Detector,代碼行數:9,代碼來源:graph_builder_test.py

示例13: load_model

# 需要導入模塊: from dragnn.protos import spec_pb2 [as 別名]
# 或者: from dragnn.protos.spec_pb2 import MasterSpec [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


注:本文中的dragnn.protos.spec_pb2.MasterSpec方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。