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


Python tensor_util.constant_value_as_shape方法代码示例

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


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

示例1: _TileGradShape

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def _TileGradShape(op):
  """Shape function for the TileGrad op."""
  multiples_shape = op.inputs[1].get_shape().with_rank(1)
  input_shape = op.inputs[0].get_shape().with_rank(multiples_shape[0])
  # NOTE(mrry): Represent `multiples` as a `TensorShape` because (i)
  # it is a vector of non-negative integers, and (ii) doing so allows
  # us to handle partially-known multiples.
  multiples = tensor_util.constant_value_as_shape(op.inputs[1]).with_rank(
      input_shape.ndims)
  if multiples.ndims is None:
    return [tensor_shape.unknown_shape()]
  else:
    output_dims = []
    for dim, multiple in zip(input_shape.dims, multiples.dims):
      output_dims.append(dim // multiple)
    return [tensor_shape.TensorShape(output_dims)] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:18,代码来源:array_ops.py

示例2: _FillShape

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def _FillShape(op):
  """Shape function for the Fill op.

  This op takes a vector of dimensions and a scalar, and produces a
  tensor with the given dimensions.

  Args:
    op: A Fill Operation.

  Returns:
    A single-element list containing the shape of the output.

  Raises:
    ValueError: If the shapes or arguments are known to be invalid.
  """
  op.inputs[0].get_shape().assert_has_rank(1)
  op.inputs[1].get_shape().assert_has_rank(0)
  fill_dims = tensor_util.constant_value(op.inputs[0])
  if fill_dims is not None and any(d < 0 for d in fill_dims):
    raise ValueError("Fill dimensions must be >= 0")
  return [tensor_util.constant_value_as_shape(op.inputs[0])] 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:array_ops.py

示例3: get_shape

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def get_shape(self):
    """Get the `TensorShape` representing the shape of the dense tensor.

    Returns:
      A `TensorShape` object.
    """
    return tensor_util.constant_value_as_shape(self._dense_shape) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:sparse_tensor.py

示例4: output_shapes

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def output_shapes(self):
    def _padded_shape_to_batch_shape(s):
      return tensor_shape.vector(None).concatenate(
          tensor_util.constant_value_as_shape(s))
    return nest.map_structure(_padded_shape_to_batch_shape, self._padded_shapes) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:7,代码来源:dataset_ops.py

示例5: _to_batched_tensor_list

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def _to_batched_tensor_list(self, value):
    if self._dense_shape.merge_with(
        tensor_util.constant_value_as_shape(value.dense_shape)).ndims == 0:
      raise ValueError(
          "Unbatching a sparse tensor is only supported for rank >= 1")
    return [sparse_ops.serialize_many_sparse(value, out_type=dtypes.variant)] 
开发者ID:yyht,项目名称:BERT,代码行数:8,代码来源:strcuture.py

示例6: from_value

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def from_value(value):
    sparse_tensor = sparse_tensor_lib.SparseTensor.from_value(value)
    return SparseTensorStructure(
        sparse_tensor.dtype,
        tensor_util.constant_value_as_shape(sparse_tensor.dense_shape)) 
开发者ID:yyht,项目名称:BERT,代码行数:7,代码来源:strcuture.py

示例7: _SliceShape

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def _SliceShape(op):
  """Shape function for array_ops.slice."""
  input_shape = op.inputs[0].get_shape()
  begin_shape = op.inputs[1].get_shape().with_rank(1)
  sizes_shape = op.inputs[2].get_shape().with_rank(1)
  ndims = begin_shape.merge_with(sizes_shape)[0].value
  if ndims is not None:
    input_shape.assert_has_rank(ndims)
  # NOTE(mrry): Use `constant_value_as_shape()` to handle
  # partially-known values.
  begin_value = tensor_util.constant_value_as_shape(
      op.inputs[1]).with_rank(ndims)
  # NOTE(mrry): We can't use `constant_value_as_shape()` for `sizes`
  # because it might contain -1, which can't be represented as a
  # `TensorShape`.
  sizes_value = tensor_util.constant_value(op.inputs[2])
  if sizes_value is not None:
    returned_dims = []
    for i, (slice_size, begin_dim) in enumerate(zip(sizes_value.ravel(),
                                                    begin_value.dims)):
      if slice_size != -1:
        returned_dims.append(slice_size)
      else:
        returned_dims.append(input_shape[i] - begin_dim)
    return [tensor_shape.TensorShape(returned_dims)]
  else:
    if input_shape.ndims is not None:
      return [tensor_shape.unknown_shape(ndims=input_shape.ndims)]
    elif ndims is not None:
      return [tensor_shape.unknown_shape(ndims=ndims)]
    else:
      return [tensor_shape.unknown_shape()] 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:34,代码来源:array_ops.py

示例8: _ReshapeShape

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def _ReshapeShape(op):
  """Shape function for Reshape op."""
  input_shape = op.inputs[0].get_shape()
  if input_shape.ndims is not None:
    num_elements = tensor_shape.Dimension(1)
    for dim in input_shape.dims:
      num_elements *= dim
  else:
    num_elements = tensor_shape.Dimension(None)
  new_shape = tensor_util.constant_value_as_shape(op.inputs[1])
  if new_shape.ndims is None:
    # We have no information about the shape of the output.
    return [new_shape]
  if None not in new_shape.as_list():
    # The new shape is fully defined.
    if (num_elements.value is not None
        and num_elements.value != np.prod(new_shape)):
      raise ValueError(
          "Cannot reshape a tensor with %d elements to shape %s (%d elements)"
          % (num_elements.value, new_shape, np.prod(new_shape)))
  elif num_elements.value is not None:
    # We know the number of elements, so we can calculate the missing
    # dimension in the new_shape.
    known_elements = 1
    unknown_indices = []
    for i, dim in enumerate(new_shape):
      if dim.value is None:
        unknown_indices.append(i)
      else:
        known_elements *= dim.value
    if known_elements != 0:
      if num_elements % known_elements != 0:
        raise ValueError("input has %s elements, which isn't divisible by %d" %
                         (num_elements, known_elements))
      if len(unknown_indices) == 1:
        unknown_index = unknown_indices[0]
        new_shape = new_shape.merge_with(
            new_shape[:unknown_index].concatenate(
                [num_elements // known_elements]).concatenate(
                    new_shape[unknown_index+1:]))
  return [new_shape] 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:43,代码来源:array_ops.py

示例9: _TileShape

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def _TileShape(op):
  """Shape function for the Tile op.

  This op has two inputs:

  * input: A rank-N tensor.
  * multiples: A length-N vector, in which the i^th element contains
    the factor by which `input` will be tiled in the i^th dimension.

  It has one output, which has the same rank as input, and additional
  elements according to the values in multiples

  Args:
    op: A Tile Operation.

  Returns:
    A single-element list containing the shape of the output.
  """
  multiples_shape = op.inputs[1].get_shape().with_rank(1)
  input_shape = op.inputs[0].get_shape().with_rank(multiples_shape[0].value)
  # NOTE(mrry): Represent `multiples` as a `TensorShape` because (i)
  # it is a vector of non-negative integers, and (ii) doing so allows
  # us to handle partially-known multiples.
  multiples = tensor_util.constant_value_as_shape(op.inputs[1]).with_rank(
      input_shape.ndims)
  if multiples.ndims is None:
    return [tensor_shape.unknown_shape()]
  else:
    output_dims = []
    for dim, multiple in zip(input_shape.dims, multiples.dims):
      output_dims.append(dim * multiple)
    return [tensor_shape.TensorShape(output_dims)] 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:34,代码来源:array_ops.py

示例10: testConstant

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def testConstant(self):
    np_val = np.random.rand(3).astype(np.int32)
    tf_val = tf.constant(np_val)
    self.assertEqual(tf.TensorShape(np_val),
                     tensor_util.constant_value_as_shape(tf_val))

    tf_val = tf.constant([], dtype=tf.int32)
    self.assertEqual(tf.TensorShape([]),
                     tensor_util.constant_value_as_shape(tf_val)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:11,代码来源:tensor_util_test.py

示例11: testShape

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def testShape(self):
    tf_val = tf.shape(tf.constant(0.0, shape=[1, 2, 3]))
    c_val = tensor_util.constant_value_as_shape(tf_val)
    self.assertEqual(tf.TensorShape([1, 2, 3]), c_val) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:6,代码来源:tensor_util_test.py

示例12: testPack

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def testPack(self):
    tf_val = tf.stack([tf.constant(16), 37, tf.placeholder(tf.int32)])
    c_val = tensor_util.constant_value_as_shape(tf_val)
    self.assertEqual([16, 37, None], c_val.as_list()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:6,代码来源:tensor_util_test.py

示例13: testConcat

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def testConcat(self):
    tf_val = tf.concat(0, [[16, 37], tf.placeholder(tf.int32, shape=(2,))])
    c_val = tensor_util.constant_value_as_shape(tf_val)
    self.assertEqual([16, 37, None, None], c_val.as_list())

    tf_val = tf.concat(0,
                       [[16, 37], tf.placeholder(tf.int32, shape=(1,)), [48]])
    c_val = tensor_util.constant_value_as_shape(tf_val)
    self.assertEqual([16, 37, None, 48], c_val.as_list()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:11,代码来源:tensor_util_test.py

示例14: get_shape

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def get_shape(self):
    """Get the `TensorShape` that represents the shape of the dense tensor.

    Returns:
      A `TensorShape` object.
    """
    return tensor_util.constant_value_as_shape(self._shape) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:9,代码来源:sparse_tensor.py

示例15: output_shapes

# 需要导入模块: from tensorflow.python.framework import tensor_util [as 别名]
# 或者: from tensorflow.python.framework.tensor_util import constant_value_as_shape [as 别名]
def output_shapes(self):

    def _padded_shape_to_batch_shape(s):
      return tensor_shape.vector(None).concatenate(
          tensor_util.constant_value_as_shape(s))

    return nest.map_structure(_padded_shape_to_batch_shape, self._padded_shapes) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:9,代码来源:dataset_ops.py


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