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


Python tensorflow.sparse_reshape方法代码示例

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


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

示例1: testFeedPartialShapes

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedPartialShapes(self):
    with self.test_session(use_gpu=False):
      # Incorporate new rank into shape information if known
      sp_input = self._SparseTensorPlaceholder()
      sp_output = tf.sparse_reshape(sp_input, [2, 3, 5])
      self.assertListEqual(sp_output.indices.get_shape().as_list(), [None, 3])
      self.assertListEqual(sp_output.shape.get_shape().as_list(), [3])

      # Incorporate known shape information about input indices in output
      # indices
      sp_input = self._SparseTensorPlaceholder()
      sp_input.indices.set_shape([5, None])
      sp_output = tf.sparse_reshape(sp_input, [2, 3, 5])
      self.assertListEqual(sp_output.indices.get_shape().as_list(), [5, 3])
      self.assertListEqual(sp_output.shape.get_shape().as_list(), [3])

      # Even if new_shape has no shape information, we know the ranks of
      # output indices and shape
      sp_input = self._SparseTensorPlaceholder()
      sp_input.indices.set_shape([5, None])
      new_shape = tf.placeholder(tf.int64)
      sp_output = tf.sparse_reshape(sp_input, new_shape)
      self.assertListEqual(sp_output.indices.get_shape().as_list(), [5, None])
      self.assertListEqual(sp_output.shape.get_shape().as_list(), [None]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:26,代码来源:sparse_reshape_op_test.py

示例2: get_sp_topk

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [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

示例3: tensors_to_item

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [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

示例4: testSameShape

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testSameShape(self):
    with self.test_session(use_gpu=False) as sess:
      input_val = self._SparseTensorValue_5x6()
      sp_output = tf.sparse_reshape(input_val, [5, 6])

      output_val = sess.run(sp_output)
      self.assertAllEqual(output_val.indices, input_val.indices)
      self.assertAllEqual(output_val.values, input_val.values)
      self.assertAllEqual(output_val.shape, input_val.shape) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:11,代码来源:sparse_reshape_op_test.py

示例5: testFeedSameShape

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedSameShape(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensorPlaceholder()
      input_val = self._SparseTensorValue_5x6()
      sp_output = tf.sparse_reshape(sp_input, [5, 6])

      output_val = sess.run(sp_output, {sp_input: input_val})
      self.assertAllEqual(output_val.indices, input_val.indices)
      self.assertAllEqual(output_val.values, input_val.values)
      self.assertAllEqual(output_val.shape, input_val.shape) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:12,代码来源:sparse_reshape_op_test.py

示例6: testFeedSameShapeWithInferredDim

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedSameShapeWithInferredDim(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensorPlaceholder()
      input_val = self._SparseTensorValue_5x6()
      sp_output = tf.sparse_reshape(sp_input, [-1, 6])

      output_val = sess.run(sp_output, {sp_input: input_val})
      self.assertAllEqual(output_val.indices, input_val.indices)
      self.assertAllEqual(output_val.values, input_val.values)
      self.assertAllEqual(output_val.shape, input_val.shape) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:12,代码来源:sparse_reshape_op_test.py

示例7: testFeedNewShapeSameRank

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedNewShapeSameRank(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensorPlaceholder()
      input_val = self._SparseTensorValue_5x6()
      sp_output = tf.sparse_reshape(sp_input, [3, 10])

      output_val = sess.run(sp_output, {sp_input: input_val})
      self.assertAllEqual(output_val.indices, np.array([
          [0, 0], [0, 6], [0, 9], [1, 0], [2, 0], [2, 1]
      ]))
      self.assertAllEqual(output_val.values, input_val.values)
      self.assertAllEqual(output_val.shape, [3, 10]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:sparse_reshape_op_test.py

示例8: testFeedNewShapeSameRankWithInferredDim

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedNewShapeSameRankWithInferredDim(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensorPlaceholder()
      input_val = self._SparseTensorValue_5x6()
      sp_output = tf.sparse_reshape(sp_input, [3, -1])

      output_val = sess.run(sp_output, {sp_input: input_val})
      self.assertAllEqual(output_val.indices, np.array([
          [0, 0], [0, 6], [0, 9], [1, 0], [2, 0], [2, 1]
      ]))
      self.assertAllEqual(output_val.values, input_val.values)
      self.assertAllEqual(output_val.shape, [3, 10]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:sparse_reshape_op_test.py

示例9: testFeedUpRank

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedUpRank(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensorPlaceholder()
      input_val = self._SparseTensorValue_5x6()
      sp_output = tf.sparse_reshape(sp_input, [2, 3, 5])

      output_val = sess.run(sp_output, {sp_input: input_val})
      self.assertAllEqual(output_val.indices, np.array([
          [0, 0, 0], [0, 1, 1], [0, 1, 4], [0, 2, 0], [1, 1, 0], [1, 1, 1]
      ]))
      self.assertAllEqual(output_val.values, input_val.values)
      self.assertAllEqual(output_val.shape, [2, 3, 5]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:sparse_reshape_op_test.py

示例10: testFeedUpRankWithInferredDim

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedUpRankWithInferredDim(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensorPlaceholder()
      input_val = self._SparseTensorValue_5x6()
      sp_output = tf.sparse_reshape(sp_input, [2, -1, 5])

      output_val = sess.run(sp_output, {sp_input: input_val})
      self.assertAllEqual(output_val.indices, np.array([
          [0, 0, 0], [0, 1, 1], [0, 1, 4], [0, 2, 0], [1, 1, 0], [1, 1, 1]
      ]))
      self.assertAllEqual(output_val.values, input_val.values)
      self.assertAllEqual(output_val.shape, [2, 3, 5]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:sparse_reshape_op_test.py

示例11: testFeedDownRank

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedDownRank(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensorPlaceholder()
      input_val = self._SparseTensorValue_2x3x4()
      sp_output = tf.sparse_reshape(sp_input, [6, 4])

      output_val = sess.run(sp_output, {sp_input: input_val})
      self.assertAllEqual(output_val.indices, np.array([
          [0, 1], [1, 0], [1, 2], [3, 3], [4, 1], [4, 3], [5, 2]
      ]))
      self.assertAllEqual(output_val.values, input_val.values)
      self.assertAllEqual(output_val.shape, [6, 4]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:sparse_reshape_op_test.py

示例12: testFeedDownRankWithInferredDim

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedDownRankWithInferredDim(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensorPlaceholder()
      input_val = self._SparseTensorValue_2x3x4()
      sp_output = tf.sparse_reshape(sp_input, [6, -1])

      output_val = sess.run(sp_output, {sp_input: input_val})
      self.assertAllEqual(output_val.indices, np.array([
          [0, 1], [1, 0], [1, 2], [3, 3], [4, 1], [4, 3], [5, 2]
      ]))
      self.assertAllEqual(output_val.values, input_val.values)
      self.assertAllEqual(output_val.shape, [6, 4]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:14,代码来源:sparse_reshape_op_test.py

示例13: testFeedMultipleInferredDims

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedMultipleInferredDims(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensorPlaceholder()
      input_val = self._SparseTensorValue_5x6()
      sp_output = tf.sparse_reshape(sp_input, [4, -1, -1])
      with self.assertRaisesOpError("only one output shape size may be -1"):
        sess.run(sp_output, {sp_input: input_val}) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:9,代码来源:sparse_reshape_op_test.py

示例14: testFeedMismatchedSizesWithInferredDim

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedMismatchedSizesWithInferredDim(self):
    with self.test_session(use_gpu=False) as sess:
      sp_input = self._SparseTensorPlaceholder()
      input_val = self._SparseTensorValue_5x6()
      sp_output = tf.sparse_reshape(sp_input, [4, -1])
      with self.assertRaisesOpError("requested shape requires a multiple"):
        sess.run(sp_output, {sp_input: input_val}) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:9,代码来源:sparse_reshape_op_test.py

示例15: testFeedDenseReshapeSemantics

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_reshape [as 别名]
def testFeedDenseReshapeSemantics(self):
    with self.test_session(use_gpu=False) as sess:
      # Compute a random rank-5 initial shape and new shape, randomly sparsify
      # it, and check that the output of SparseReshape has the same semantics
      # as a dense reshape.
      factors = np.array([2] * 4 + [3] * 4 + [5] * 4)  # 810k total elements
      orig_rank = np.random.randint(2, 7)
      orig_map = np.random.randint(orig_rank, size=factors.shape)
      orig_shape = [np.prod(factors[orig_map == d]) for d in range(orig_rank)]
      new_rank = np.random.randint(2, 7)
      new_map = np.random.randint(new_rank, size=factors.shape)
      new_shape = [np.prod(factors[new_map == d]) for d in range(new_rank)]

      orig_dense = np.random.uniform(size=orig_shape)
      orig_indices = np.transpose(np.nonzero(orig_dense < 0.5))
      orig_values = orig_dense[orig_dense < 0.5]

      new_dense = np.reshape(orig_dense, new_shape)
      new_indices = np.transpose(np.nonzero(new_dense < 0.5))
      new_values = new_dense[new_dense < 0.5]

      sp_input = self._SparseTensorPlaceholder()
      input_val = tf.SparseTensorValue(orig_indices, orig_values, orig_shape)
      sp_output = tf.sparse_reshape(sp_input, new_shape)

      output_val = sess.run(sp_output, {sp_input: input_val})
      self.assertAllEqual(output_val.indices, new_indices)
      self.assertAllEqual(output_val.values, new_values)
      self.assertAllEqual(output_val.shape, new_shape) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:31,代码来源:sparse_reshape_op_test.py


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