當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。