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


Python network_units.GatherNetwork方法代碼示例

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


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

示例1: setUp

# 需要導入模塊: from dragnn.python import network_units [as 別名]
# 或者: from dragnn.python.network_units import GatherNetwork [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()
    text_format.Parse("""
      component {
        name: 'test'
        backend { registered_name: 'TestComponent' }
        linked_feature {
          name: 'indices'
          fml: 'input.focus'
          size: 1
          embedding_dim: -1
          source_component: 'previous'
          source_translator: 'identity'
          source_layer: 'index_layer'
        }
        linked_feature {
          name: 'features'
          fml: 'input.focus'
          size: 1
          embedding_dim: -1
          source_component: 'previous'
          source_translator: 'identity'
          source_layer: 'feature_layer'
        }
        network_unit {
          registered_name: 'GatherNetwork'
        }
      }
    """, self._master.spec)
    self._component = MockComponent(self._master,
                                    self._master.spec.component[0])
    self._master.lookup_component['previous'].network = MockNetwork(
        index_layer=1, feature_layer=2) 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:40,代碼來源:network_units_test.py

示例2: testConstantPadding

# 需要導入模塊: from dragnn.python import network_units [as 別名]
# 或者: from dragnn.python.network_units import GatherNetwork [as 別名]
def testConstantPadding(self):
    with tf.Graph().as_default(), self.test_session():
      with tf.variable_scope('test_scope'):
        network = network_units.GatherNetwork(self._component)

      # Construct a batch of two items with 3 and 2 steps, respectively.
      indices = tf.constant([[1], [2], [0],  # item 1
                             [-1], [0], [-1]],  # item 2
                            dtype=tf.int64)
      features = tf.constant([[1.0, 1.5], [2.0, 2.5], [3.0, 3.5],  # item 1
                              [4.0, 4.5], [5.0, 5.5], [6.0, 6.5]],  # item 2
                             dtype=tf.float32)

      fixed_embeddings = []
      linked_embeddings = [
          network_units.NamedTensor(indices, 'indices', 1),
          network_units.NamedTensor(features, 'features', 2)
      ]

      with tf.variable_scope('test_scope', reuse=True):
        outputs = network.create(fixed_embeddings, linked_embeddings, None,
                                 None, True, 2)
      gathered = outputs[0]

      # Zeros will be substituted for index -1.
      self.assertAllEqual(gathered.eval(),
                          [[2.0, 2.5],  # gathered from 1
                           [3.0, 3.5],  # gathered from 2
                           [1.0, 1.5],  # gathered from 0
                           [0.0, 0.0],  # gathered from -1
                           [4.0, 4.5],  # gathered from 0
                           [0.0, 0.0]])  # gathered from -1 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:34,代碼來源:network_units_test.py

示例3: testTrainablePadding

# 需要導入模塊: from dragnn.python import network_units [as 別名]
# 或者: from dragnn.python.network_units import GatherNetwork [as 別名]
def testTrainablePadding(self):
    self._component.spec.network_unit.parameters['trainable_padding'] = 'true'
    with tf.Graph().as_default(), self.test_session():
      with tf.variable_scope('test_scope'):
        network = network_units.GatherNetwork(self._component)

      # Construct a batch of two items with 3 and 2 steps, respectively.
      indices = tf.constant([[1], [2], [0],  # item 1
                             [-1], [0], [-1]],  # item 2
                            dtype=tf.int64)
      features = tf.constant([[1.0, 1.5], [2.0, 2.5], [3.0, 3.5],  # item 1
                              [4.0, 4.5], [5.0, 5.5], [6.0, 6.5]],  # item 2
                             dtype=tf.float32)

      fixed_embeddings = []
      linked_embeddings = [
          network_units.NamedTensor(indices, 'indices', 1),
          network_units.NamedTensor(features, 'features', 2)
      ]

      with tf.variable_scope('test_scope', reuse=True):
        outputs = network.create(fixed_embeddings, linked_embeddings, None,
                                 None, True, 2)
      gathered = outputs[0]

      # Ensure that the padding variable is initialized.
      tf.global_variables_initializer().run()

      # Randomly-initialized padding will be substituted for index -1.
      self.assertAllEqual(gathered[0].eval(), [2.0, 2.5])  # gathered from 1
      self.assertAllEqual(gathered[1].eval(), [3.0, 3.5])  # gathered from 2
      self.assertAllEqual(gathered[2].eval(), [1.0, 1.5])  # gathered from 0
      tf.logging.info('padding = %s', gathered[3].eval())  # gathered from -1
      self.assertAllEqual(gathered[4].eval(), [4.0, 4.5])  # gathered from 0
      tf.logging.info('padding = %s', gathered[5].eval())  # gathered from -1

      # Though random, the padding must identical.
      self.assertAllEqual(gathered[3].eval(), gathered[5].eval()) 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:40,代碼來源:network_units_test.py

示例4: testConstantPadding

# 需要導入模塊: from dragnn.python import network_units [as 別名]
# 或者: from dragnn.python.network_units import GatherNetwork [as 別名]
def testConstantPadding(self):
    with tf.Graph().as_default(), self.test_session():
      with tf.variable_scope('test_scope'):
        network = network_units.GatherNetwork(self._component)

      # Construct a batch of two items with 3 and 2 steps, respectively.
      indices = tf.constant(
          [
              # item 1
              [1],
              [2],
              [0],
              # item 2
              [-1],
              [0],
              [-1]
          ],
          dtype=tf.int64)
      features = tf.constant(
          [
              # item 1
              [1.0, 1.5],
              [2.0, 2.5],
              [3.0, 3.5],
              # item 2
              [4.0, 4.5],
              [5.0, 5.5],
              [6.0, 6.5]
          ],
          dtype=tf.float32)

      fixed_embeddings = []
      linked_embeddings = [
          network_units.NamedTensor(indices, 'indices', 1),
          network_units.NamedTensor(features, 'features', 2)
      ]

      with tf.variable_scope('test_scope', reuse=True):
        outputs = network.create(fixed_embeddings, linked_embeddings, None,
                                 None, True, 2)
      gathered = outputs[0]

      # Zeros will be substituted for index -1.
      self.assertAllEqual(
          gathered.eval(),
          [
              [2.0, 2.5],  # gathered from 1
              [3.0, 3.5],  # gathered from 2
              [1.0, 1.5],  # gathered from 0
              [0.0, 0.0],  # gathered from -1
              [4.0, 4.5],  # gathered from 0
              [0.0, 0.0]  # gathered from -1
          ]) 
開發者ID:generalized-iou,項目名稱:g-tensorflow-models,代碼行數:55,代碼來源:network_units_test.py

示例5: testTrainablePadding

# 需要導入模塊: from dragnn.python import network_units [as 別名]
# 或者: from dragnn.python.network_units import GatherNetwork [as 別名]
def testTrainablePadding(self):
    self._component.spec.network_unit.parameters['trainable_padding'] = 'true'
    with tf.Graph().as_default(), self.test_session():
      with tf.variable_scope('test_scope'):
        network = network_units.GatherNetwork(self._component)

      # Construct a batch of two items with 3 and 2 steps, respectively.
      indices = tf.constant(
          [
              # item 1
              [1],
              [2],
              [0],
              # item 2
              [-1],
              [0],
              [-1]
          ],
          dtype=tf.int64)
      features = tf.constant(
          [
              # item 1
              [1.0, 1.5],
              [2.0, 2.5],
              [3.0, 3.5],
              # item 2
              [4.0, 4.5],
              [5.0, 5.5],
              [6.0, 6.5]
          ],
          dtype=tf.float32)

      fixed_embeddings = []
      linked_embeddings = [
          network_units.NamedTensor(indices, 'indices', 1),
          network_units.NamedTensor(features, 'features', 2)
      ]

      with tf.variable_scope('test_scope', reuse=True):
        outputs = network.create(fixed_embeddings, linked_embeddings, None,
                                 None, True, 2)
      gathered = outputs[0]

      # Ensure that the padding variable is initialized.
      tf.global_variables_initializer().run()

      # Randomly-initialized padding will be substituted for index -1.
      self.assertAllEqual(gathered[0].eval(), [2.0, 2.5])  # gathered from 1
      self.assertAllEqual(gathered[1].eval(), [3.0, 3.5])  # gathered from 2
      self.assertAllEqual(gathered[2].eval(), [1.0, 1.5])  # gathered from 0
      tf.logging.info('padding = %s', gathered[3].eval())  # gathered from -1
      self.assertAllEqual(gathered[4].eval(), [4.0, 4.5])  # gathered from 0
      tf.logging.info('padding = %s', gathered[5].eval())  # gathered from -1

      # Though random, the padding must identical.
      self.assertAllEqual(gathered[3].eval(), gathered[5].eval()) 
開發者ID:generalized-iou,項目名稱:g-tensorflow-models,代碼行數:58,代碼來源:network_units_test.py


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