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


Python tensorflow.sparse_concat方法代码示例

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


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

示例1: concatenate

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def concatenate(tensors, axis=-1):
    """Concatenates a list of tensors alongside the specified axis.

    # Arguments
        tensors: list of tensors to concatenate.
        axis: concatenation axis.

    # Returns
        A tensor.
    """
    if axis < 0:
        rank = ndim(tensors[0])
        if rank:
            axis %= rank
        else:
            axis = 0

    if py_all([is_sparse(x) for x in tensors]):
        return tf.sparse_concat(axis, tensors)
    else:
        return tf.concat([to_dense(x) for x in tensors], axis) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:23,代码来源:tensorflow_backend.py

示例2: testConcat1

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def testConcat1(self):
    with self.test_session(use_gpu=False) as sess:
      # concat(A):
      # [    1]
      # [2    ]
      # [3   4]
      for sp_a in (self._SparseTensorValue_3x3(), self._SparseTensor_3x3()):
        # Note that we ignore concat_dim in this case since we short-circuit the
        # single-input case in python.
        for concat_dim in (-2000, 1, 2000):
          sp_concat = tf.sparse_concat(concat_dim, [sp_a])

          self.assertEqual(sp_concat.indices.get_shape(), [4, 2])
          self.assertEqual(sp_concat.values.get_shape(), [4])
          self.assertEqual(sp_concat.shape.get_shape(), [2])

          concat_out = sess.run(sp_concat)

          self.assertAllEqual(concat_out.indices,
                              [[0, 2], [1, 0], [2, 0], [2, 2]])
          self.assertAllEqual(concat_out.values, [1, 2, 3, 4])
          self.assertAllEqual(concat_out.shape, [3, 3]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:sparse_concat_op_test.py

示例3: testConcat2

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def testConcat2(self):
    with self.test_session(use_gpu=False) as sess:
      # concat(A, B):
      # [    1          ]
      # [2       1      ]
      # [3   4 2     1 0]
      for sp_a in (self._SparseTensorValue_3x3(), self._SparseTensor_3x3()):
        for sp_b in (self._SparseTensorValue_3x5(), self._SparseTensor_3x5()):
          for concat_dim in (-1, 1):
            sp_concat = tf.sparse_concat(concat_dim, [sp_a, sp_b])

            self.assertEqual(sp_concat.indices.get_shape(), [8, 2])
            self.assertEqual(sp_concat.values.get_shape(), [8])
            self.assertEqual(sp_concat.shape.get_shape(), [2])

            concat_out = sess.run(sp_concat)

            self.assertAllEqual(concat_out.indices, [[0, 2], [1, 0], [1, 4],
                                                     [2, 0], [2, 2], [2, 3],
                                                     [2, 6], [2, 7]])
            self.assertAllEqual(concat_out.values, [1, 2, 1, 3, 4, 2, 1, 0])
            self.assertAllEqual(concat_out.shape, [3, 8]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:sparse_concat_op_test.py

示例4: testConcatDim0

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def testConcatDim0(self):
    with self.test_session(use_gpu=False) as sess:
      # concat(A, D):
      # [    1]
      # [2    ]
      # [3   4]
      # [  1  ]
      # [1   2]
      sp_a = self._SparseTensor_3x3()
      sp_d = self._SparseTensor_2x3()

      for concat_dim in (-2, 0):
        sp_concat = tf.sparse_concat(concat_dim, [sp_a, sp_d])

        self.assertEqual(sp_concat.indices.get_shape(), [7, 2])
        self.assertEqual(sp_concat.values.get_shape(), [7])
        self.assertEqual(sp_concat.shape.get_shape(), [2])

        concat_out = sess.run(sp_concat)

        self.assertAllEqual(
            concat_out.indices,
            [[0, 2], [1, 0], [2, 0], [2, 2], [3, 1], [4, 0], [4, 2]])
        self.assertAllEqual(concat_out.values, np.array([1, 2, 3, 4, 1, 1, 2]))
        self.assertAllEqual(concat_out.shape, np.array([5, 3])) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:sparse_concat_op_test.py

示例5: testConcat3

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def testConcat3(self):
    with self.test_session(use_gpu=False) as sess:
      # concat(A, B, C):
      # [    1              ]
      # [2       1       1  ]
      # [3   4 2     1 0 2  ]
      sp_a = self._SparseTensor_3x3()
      sp_b = self._SparseTensor_3x5()
      sp_c = self._SparseTensor_3x2()

      for concat_dim in (-1, 1):
        sp_concat = tf.sparse_concat(concat_dim, [sp_a, sp_b, sp_c])

        self.assertEqual(sp_concat.indices.get_shape(), [10, 2])
        self.assertEqual(sp_concat.values.get_shape(), [10])
        self.assertEqual(sp_concat.shape.get_shape(), [2])

        concat_out = sess.run(sp_concat)

        self.assertAllEqual(concat_out.indices, [[0, 2], [1, 0], [1, 4], [1, 8],
                                                 [2, 0], [2, 2], [2, 3], [2, 6],
                                                 [2, 7], [2, 8]])
        self.assertAllEqual(concat_out.values, [1, 2, 1, 1, 3, 4, 2, 1, 0, 2])
        self.assertAllEqual(concat_out.shape, [3, 10]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:26,代码来源:sparse_concat_op_test.py

示例6: get_sp_topk

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def get_sp_topk(adj_pred, sp_adj_train, nb_nodes, k):
  """Returns binary matrix with topK."""
  _, indices = tf.nn.top_k(tf.reshape(adj_pred, (-1,)), k)
  indices = tf.reshape(tf.cast(indices, tf.int64), (-1, 1))
  sp_adj_pred = tf.SparseTensor(
      indices=indices,
      values=tf.ones(k),
      dense_shape=(nb_nodes * nb_nodes,))
  sp_adj_pred = tf.sparse_reshape(sp_adj_pred,
                                  shape=(nb_nodes, nb_nodes, 1))
  sp_adj_train = tf.SparseTensor(
      indices=sp_adj_train.indices,
      values=tf.ones_like(sp_adj_train.values),
      dense_shape=sp_adj_train.dense_shape)
  sp_adj_train = tf.sparse_reshape(sp_adj_train,
                                   shape=(nb_nodes, nb_nodes, 1))
  sp_adj_pred = tf.sparse_concat(
      sp_inputs=[sp_adj_pred, sp_adj_train], axis=-1)
  return tf.sparse_reduce_max(sp_adj_pred, axis=-1) 
开发者ID:google,项目名称:gcnn-survey-paper,代码行数:21,代码来源:model_utils.py

示例7: compute_inference

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def compute_inference(self, node_features_in, sp_adj_matrix, is_training):
    with tf.variable_scope('edge-model'):
      z_latent = gcn_module(node_features_in, sp_adj_matrix, self.n_hidden_edge,
                            self.p_drop_edge, is_training, self.input_dim,
                            self.sparse_features)
      adj_matrix_pred = compute_adj(z_latent, self.att_mechanism,
                                    self.p_drop_edge, is_training)
      self.adj_matrix_pred = adj_matrix_pred
    with tf.variable_scope('node-model'):
      z_latent = tf.sparse_concat(
          axis=1,
          sp_inputs=[
              tf.contrib.layers.dense_to_sparse(z_latent), node_features_in
          ])
      sparse_features = True
      input_dim = self.n_hidden_edge[-1] + self.input_dim
      logits = gcn_module(
          z_latent,
          sp_adj_matrix,
          self.n_hidden_node,
          self.p_drop_node,
          is_training,
          input_dim,
          sparse_features=sparse_features)
    return logits, adj_matrix_pred 
开发者ID:google,项目名称:gcnn-survey-paper,代码行数:27,代码来源:node_edge_models.py

示例8: tensors_to_item

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def tensors_to_item(self, keys_to_tensors):
    """Maps the given dictionary of tensors to a concatenated list of bboxes.

    Args:
      keys_to_tensors: a mapping of TF-Example keys to parsed tensors.

    Returns:
      [time, num_boxes, 4] tensor of bounding box coordinates, in order
          [y_min, x_min, y_max, x_max]. Whether the tensor is a SparseTensor
          or a dense Tensor is determined by the return_dense parameter. Empty
          positions in the sparse tensor are filled with -1.0 values.
    """
    sides = []
    for key in self._full_keys:
      value = keys_to_tensors[key]
      expanded_dims = tf.concat(
          [tf.to_int64(tf.shape(value)),
           tf.constant([1], dtype=tf.int64)], 0)
      side = tf.sparse_reshape(value, expanded_dims)
      sides.append(side)
    bounding_boxes = tf.sparse_concat(2, sides)
    if self._return_dense:
      bounding_boxes = tf.sparse_tensor_to_dense(
          bounding_boxes, default_value=self._default_value)
    return bounding_boxes 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:27,代码来源:tf_sequence_example_decoder.py

示例9: concat_padded

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def concat_padded(list_of_tensors: List[tf.Tensor], axis: int = 0,
                  expand_nonconcat_dim: bool = True) -> tf.Tensor:
    """
    Concatenate tensors and pad tensors with smaller dimension.
    Uses sparse concatenation inside, so can be slow

    Parameters
    ----------
    list_of_tensors
        list of tensors
    axis
        axis to concatenate
    expand_nonconcat_dim
        whether to allow the expansion in the non-concat dimensions.

    Returns
    -------
    concatenated_tensor
        concatenated tensor

    """
    t_sparse = [dense_to_sparse(t, tf.shape(t, out_type=tf.int64))
                for t in list_of_tensors]
    t_concatenated_sparse = tf.sparse_concat(
        axis, t_sparse, expand_nonconcat_dim=expand_nonconcat_dim)
    return tf.sparse_tensor_to_dense(t_concatenated_sparse) 
开发者ID:audi,项目名称:nucleus7,代码行数:28,代码来源:tf_ops.py

示例10: combine_predictions_from_devices

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def combine_predictions_from_devices(
        predictions_devices: List[Dict[str, tf.Tensor]],
        predictions_have_variable_shape: bool = False) -> Dict[str, tf.Tensor]:
    """
    Combines (concatenates) the predictions from multiple devices

    Parameters
    ----------
    predictions_devices
        list of dicts with same structure from multiple devices
    predictions_have_variable_shape
        if predictions from different devices may have different shapes; if so,
        it will use sparse operations to combine them

    Returns
    -------
    dict with same structure as first element in predictions_devices with
    concatenated over first dimension (batch dimension) values. If inputs
    have variable shape, then concatenation is done using
    :obj:`tf.sparse_concat` instead of :obj:`tf.concat`
    """
    if len(predictions_devices) == 1:
        return _dict_identity(predictions_devices[0])
    if predictions_have_variable_shape:
        combine_fun = lambda x: tf_ops.concat_padded(x, axis=0)
    else:
        combine_fun = lambda x: tf_ops.concat_or_stack(x, axis=0)
    with tf.variable_scope('combine_predictions'):
        predictions = nest_utils.combine_nested(predictions_devices,
                                                combine_fun=combine_fun)
    return predictions 
开发者ID:audi,项目名称:nucleus7,代码行数:33,代码来源:model_utils.py

示例11: testSliceConcat

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def testSliceConcat(self):
    for sp_input in (
        self._SparseTensorValue_3x4x2(), self._SparseTensor_3x4x2()):
      with self.test_session(use_gpu=False):
        sparse_tensors = tf.sparse_split(1, 2, sp_input)
        concat_tensor = tf.sparse_concat(1, sparse_tensors)
        expected_output = self._SparseTensor_3x4x2()
        self.assertAllEqual(concat_tensor.indices.eval(),
                            expected_output.indices.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:11,代码来源:sparse_split_op_test.py

示例12: testMismatchedRank

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def testMismatchedRank(self):
    with self.test_session(use_gpu=False):
      sp_a = self._SparseTensor_3x3()
      sp_e = self._SparseTensor_2x3x4()

      # Rank mismatches can be caught at shape-inference time
      for concat_dim in (-1, 1):
        with self.assertRaises(ValueError):
          tf.sparse_concat(concat_dim, [sp_a, sp_e]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:11,代码来源:sparse_concat_op_test.py

示例13: testMismatchedRankExpandNonconcatDim

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def testMismatchedRankExpandNonconcatDim(self):
    with self.test_session(use_gpu=False):
      sp_a = self._SparseTensor_3x3()
      sp_e = self._SparseTensor_2x3x4()

      # Rank mismatches should be caught at shape-inference time, even for
      # expand_nonconcat_dim=True.
      for concat_dim in (-1, 1):
        with self.assertRaises(ValueError):
          tf.sparse_concat(concat_dim, [sp_a, sp_e], expand_nonconcat_dim=True) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:12,代码来源:sparse_concat_op_test.py

示例14: testMismatchedShapes

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def testMismatchedShapes(self):
    with self.test_session(use_gpu=False) as sess:
      sp_a = self._SparseTensor_3x3()
      sp_b = self._SparseTensor_3x5()
      sp_c = self._SparseTensor_3x2()
      sp_d = self._SparseTensor_2x3()
      for concat_dim in (-1, 1):
        sp_concat = tf.sparse_concat(concat_dim, [sp_a, sp_b, sp_c, sp_d])

        # Shape mismatches can only be caught when the op is run
        with self.assertRaisesOpError("Input shapes must match"):
          sess.run(sp_concat) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:sparse_concat_op_test.py

示例15: testMismatchedShapesExpandNonconcatDim

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_concat [as 别名]
def testMismatchedShapesExpandNonconcatDim(self):
    with self.test_session(use_gpu=False) as sess:
      sp_a = self._SparseTensor_3x3()
      sp_b = self._SparseTensor_3x5()
      sp_c = self._SparseTensor_3x2()
      sp_d = self._SparseTensor_2x3()
      for concat_dim0 in (-2, 0):
        for concat_dim1 in (-1, 1):
          sp_concat_dim0 = tf.sparse_concat(
              concat_dim0, [sp_a, sp_b, sp_c, sp_d], expand_nonconcat_dim=True)
          sp_concat_dim1 = tf.sparse_concat(
              concat_dim1, [sp_a, sp_b, sp_c, sp_d], expand_nonconcat_dim=True)

          sp_concat_dim0_out = sess.run(sp_concat_dim0)
          sp_concat_dim1_out = sess.run(sp_concat_dim1)

          self.assertAllEqual(sp_concat_dim0_out.indices,
                              [[0, 2], [1, 0], [2, 0], [2, 2], [4, 1], [5, 0],
                               [5, 3], [5, 4], [7, 0], [8, 0], [9, 1], [10, 0],
                               [10, 2]])
          self.assertAllEqual(sp_concat_dim0_out.values,
                              [1, 2, 3, 4, 1, 2, 1, 0, 1, 2, 1, 1, 2])
          self.assertAllEqual(sp_concat_dim0_out.shape, [11, 5])

          self.assertAllEqual(sp_concat_dim1_out.indices,
                              [[0, 2], [0, 11], [1, 0], [1, 4], [1, 8], [1, 10],
                               [1, 12], [2, 0], [2, 2], [2, 3], [2, 6], [2, 7],
                               [2, 8]])
          self.assertAllEqual(sp_concat_dim1_out.values,
                              [1, 1, 2, 1, 1, 1, 2, 3, 4, 2, 1, 0, 2])
          self.assertAllEqual(sp_concat_dim1_out.shape, [3, 13]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:33,代码来源:sparse_concat_op_test.py


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