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


Python tensor_shape.Dimension方法代码示例

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


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

示例1: testUnknownDimension

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def testUnknownDimension(self):
    dim = tensor_shape.Dimension(None)
    self.assertIs(None, dim.value)
    self.assertEqual(dim.value, tensor_shape.Dimension(None).value)
    self.assertEqual(tensor_shape.Dimension(None).value,
                     (dim + tensor_shape.Dimension(None)).value)
    self.assertEqual(tensor_shape.Dimension(None).value,
                     (dim * tensor_shape.Dimension(None)).value)
    self.assertEqual(
        tensor_shape.Dimension(None).value,
        (dim // tensor_shape.Dimension(None)).value)
    self.assertEqual(tensor_shape.Dimension(None).value,
                     dim.merge_with(tensor_shape.Dimension(None)).value)
    self.assertIs(None,
                  tensor_shape.Dimension(None) < tensor_shape.Dimension(None))
    self.assertIs(None,
                  tensor_shape.Dimension(None) <= tensor_shape.Dimension(None))
    self.assertIs(None,
                  tensor_shape.Dimension(None) > tensor_shape.Dimension(None))
    self.assertIs(None,
                  tensor_shape.Dimension(None) >= tensor_shape.Dimension(None)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:tensor_shape_test.py

示例2: testEquality

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def testEquality(self):
    self.assertTrue(tensor_shape.Dimension(12) == tensor_shape.Dimension(12))
    self.assertFalse(tensor_shape.Dimension(12) == tensor_shape.Dimension(13))
    self.assertIs(None,
                  tensor_shape.Dimension(12) == tensor_shape.Dimension(None))
    self.assertIs(None,
                  tensor_shape.Dimension(None) == tensor_shape.Dimension(12))
    self.assertIs(None,
                  tensor_shape.Dimension(None) == tensor_shape.Dimension(None))
    self.assertTrue(tensor_shape.Dimension(12) == "12")
    self.assertTrue(tensor_shape.Dimension(12) == 24.0 / 2)

    # None indicates ambiguous comparison, but comparison vs the wrong type
    # is unambigously False.
    self.assertIsNotNone(tensor_shape.Dimension(12) == "_")
    self.assertIsNotNone(tensor_shape.Dimension(None) == 12.99)
    self.assertFalse(tensor_shape.Dimension(12) == "_")
    self.assertFalse(tensor_shape.Dimension(None) == 12.99)

    self.assertIs(None, tensor_shape.Dimension(None) == "13")
    self.assertIs(None, tensor_shape.Dimension(None) == None)  # pylint: disable=g-equals-none
    self.assertFalse(tensor_shape.Dimension(12) == 12.99) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:tensor_shape_test.py

示例3: testInequality

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def testInequality(self):
    self.assertTrue(tensor_shape.Dimension(12) != tensor_shape.Dimension(13))
    self.assertFalse(tensor_shape.Dimension(12) != tensor_shape.Dimension(12))
    self.assertIs(None,
                  tensor_shape.Dimension(12) != tensor_shape.Dimension(None))
    self.assertIs(None,
                  tensor_shape.Dimension(None) != tensor_shape.Dimension(12))
    self.assertIs(None,
                  tensor_shape.Dimension(None) != tensor_shape.Dimension(None))

    # None indicates ambiguous comparison, but comparison vs the wrong type
    # is unambigously False.
    self.assertIsNotNone(tensor_shape.Dimension(12) != "_")
    self.assertIsNotNone(tensor_shape.Dimension(None) != 12.99)
    self.assertTrue(tensor_shape.Dimension(12) != "_")
    self.assertTrue(tensor_shape.Dimension(None) != 12.99)

    self.assertIs(None, tensor_shape.Dimension(None) != "13")
    self.assertIs(None, tensor_shape.Dimension(None) != None)  # pylint: disable=g-equals-none
    self.assertTrue(tensor_shape.Dimension(12) != 12.99) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:22,代码来源:tensor_shape_test.py

示例4: testFullyDefinedShape

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def testFullyDefinedShape(self):
    s = tensor_shape.TensorShape([tensor_shape.Dimension(
        3), tensor_shape.Dimension(4), tensor_shape.Dimension(7)])
    s.assert_is_fully_defined()
    self.assertEqual(3, s.ndims)
    self.assertEqual(3, len(s))
    self.assertTrue(s)
    s.assert_has_rank(3)
    self.assertEqual([tensor_shape.Dimension(3),
                      tensor_shape.Dimension(4),
                      tensor_shape.Dimension(7)], s.dims)
    self.assertEqual(tensor_shape.Dimension(3), s[0])
    self.assertEqual(tensor_shape.Dimension(4), s[1])
    self.assertEqual(tensor_shape.Dimension(7), s[2])
    self.assertEqual([3, 4, 7], s.as_list())
    s.assert_is_compatible_with([3, 4, 7])
    s.assert_same_rank([6, 3, 7])
    for d1, d2 in zip(s, [3, 4, 7]):
      assert d1.value == d2 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:tensor_shape_test.py

示例5: testConcatenate

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def testConcatenate(self):
    tensor_shape.TensorShape([1, 2, 3, 4]).assert_is_compatible_with(
        tensor_shape.TensorShape([1, 2]).concatenate(
            tensor_shape.TensorShape([3, 4])))
    tensor_shape.TensorShape([1, 2, 3, 4]).assert_is_compatible_with(
        tensor_shape.TensorShape([1, 2]).concatenate(
            tensor_shape.TensorShape(None)))
    tensor_shape.TensorShape([1, 2, 3, 4]).assert_is_compatible_with(
        tensor_shape.TensorShape(None).concatenate(
            tensor_shape.TensorShape([3, 4])))
    tensor_shape.TensorShape([1, 2, 3, 4]).assert_is_compatible_with(
        tensor_shape.TensorShape(None).concatenate(
            tensor_shape.TensorShape(None)))
    tensor_shape.TensorShape([1, 2, 3]).assert_is_compatible_with(
        tensor_shape.TensorShape([1, 2]).concatenate(
            tensor_shape.Dimension(3))) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:tensor_shape_test.py

示例6: _dimension_tensor_conversion_function

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def _dimension_tensor_conversion_function(d,
                                          dtype=None,
                                          name=None,
                                          as_ref=False):
  """Function to convert Dimension to Tensor."""
  _ = as_ref
  if d.value is None:
    raise ValueError("Cannot convert an unknown Dimension to a Tensor: %s" % d)
  if dtype is not None:
    if dtype not in (dtypes.int32, dtypes.int64):
      raise TypeError("Cannot convert a TensorShape to dtype: %s" % dtype)
  else:
    dtype = dtypes.int32
  if name is None:
    name = "shape_as_tensor"
  return constant(d.value, dtype=dtype, name=name) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:18,代码来源:constant_op.py

示例7: dequeue_many

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def dequeue_many(self, n, name=None):
    """Dequeues and concatenates `n` elements from this queue.

    This operation concatenates queue-element component tensors along
    the 0th dimension to make a single component tensor.  All of the
    components in the dequeued tuple will have size `n` in the 0th dimension.

    If the queue is closed and there are less than `n` elements left, then an
    `OutOfRange` exception is raised.

    At runtime, this operation may raise an error if the queue is
    @{tf.QueueBase.close} before or during its execution. If the
    queue is closed, the queue contains fewer than `n` elements, and
    there are no pending enqueue operations that can fulfill this
    request, `tf.errors.OutOfRangeError` will be raised. If the
    session is @{tf.Session.close},
    `tf.errors.CancelledError` will be raised.

    Args:
      n: A scalar `Tensor` containing the number of elements to dequeue.
      name: A name for the operation (optional).

    Returns:
      The tuple of concatenated tensors that was dequeued.
    """
    if name is None:
      name = "%s_DequeueMany" % self._name

    ret = gen_data_flow_ops._queue_dequeue_many_v2(
        self._queue_ref, n=n, component_types=self._dtypes, name=name)

    # NOTE(mrry): Not using a shape function because we need access to
    # the Queue object.
    op = ret[0].op
    batch_dim = tensor_shape.Dimension(tensor_util.constant_value(op.inputs[1]))
    for output, shape in zip(op.values(), self._shapes):
      output.set_shape(tensor_shape.TensorShape([batch_dim]).concatenate(shape))

    return self._dequeue_return_value(ret) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:41,代码来源:data_flow_ops.py

示例8: _dimension_tensor_conversion_function

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def _dimension_tensor_conversion_function(d, dtype=None, name=None,
                                          as_ref=False):
  _ = as_ref
  if d.value is None:
    raise ValueError("Cannot convert an unknown Dimension to a Tensor: %s" % d)
  if dtype is not None:
    if dtype not in (dtypes.int32, dtypes.int64):
      raise TypeError("Cannot convert a TensorShape to dtype: %s" % dtype)
  else:
    dtype = dtypes.int32
  if name is None:
    name = "shape_as_tensor"
  return constant(d.value, dtype=dtype, name=name) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:15,代码来源:constant_op.py

示例9: padded_batch

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def padded_batch(self, batch_size, padded_shapes, padding_values=None):
    """Combines consecutive elements of this dataset into padded batches.

    Like `Dataset.dense_to_sparse_batch()`, this method combines
    multiple consecutive elements of this dataset, which might have
    different shapes, into a single element. The tensors in the
    resulting element have an additional outer dimension, and are
    padded to the respective shape in `padded_shapes`.

    Args:
      batch_size: A `tf.int64` scalar `tf.Tensor`, representing the number of
        consecutive elements of this dataset to combine in a single batch.
      padded_shapes: A nested structure of `tf.TensorShape` or
        `tf.int64` vector tensor-like objects representing the shape
        to which the respective component of each input element should
        be padded prior to batching. Any unknown dimensions
        (e.g. `tf.Dimension(None)` in a `tf.TensorShape` or `-1` in a
        tensor-like object) will be padded to the maximum size of that
        dimension in each batch.
      padding_values: (Optional.) A nested structure of scalar-shaped
        `tf.Tensor`, representing the padding values to use for the
        respective components.  Defaults are `0` for numeric types and
        the empty string for string types.

    Returns:
      A `Dataset`.
    """
    return PaddedBatchDataset(self, batch_size, padded_shapes, padding_values) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:30,代码来源:dataset_ops.py

示例10: output_shapes

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def output_shapes(self):
    num_elements = tensor_shape.Dimension(None)
    return (tensor_shape.matrix(num_elements, self._row_shape.shape[0] + 1),
            tensor_shape.vector(num_elements),
            tensor_shape.vector(self._row_shape.shape[0] + 1)) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:7,代码来源:dataset_ops.py

示例11: _most_specific_compatible_shape

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def _most_specific_compatible_shape(s1, s2):
  """Returns the most specific shape compatible with `s1` and `s2`."""
  if s1.dims is None:
    return s1
  if s2.dims is None:
    return s2
  s1.assert_same_rank(s2)
  dims = []
  for dim1, dim2 in zip(s1, s2):
    if dim1.value is None or dim2.value is None or dim1.value != dim2.value:
      dims.append(tensor_shape.Dimension(None))
    else:
      dims.append(dim1.value)
  return tensor_shape.TensorShape(dims) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:16,代码来源:dataset_ops.py

示例12: __init__

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def __init__(self, name, value):
    """Construct an Axis.

    Args:
      name: Name of the axis.
      value: Either None, an int or tf.Dimension giving the size of the axis,
        or a sequence that is not a string additionally providing coordinate
        (tick) labels.

    Raises:
      ValueError: If the user provides labels with duplicate values.
    """
    if isinstance(value, tensor_shape.Dimension):
      dimension = value
      labels = None
    elif isinstance(value, int) or value is None:
      dimension = tensor_shape.Dimension(value)
      labels = None
    else:
      dimension = tensor_shape.Dimension(len(value))
      labels = tuple(value)

    if dimension.value == 0:
      # Treat a zero-length axis as if it has labels.
      labels = ()

    if labels is not None:
      index = dict(zip(labels, range(len(labels))))
      if len(index) != len(labels):
        raise ValueError('Tick labels must be unique, but got {}'
                         .format(labels))
    else:
      index = None

    self._name = name  # type: string_types
    self._dimension = dimension  # type: tensor_shape.Dimension
    self._labels = labels  # type: Optional[tuple]
    self._index = index  # type: Optional[Dict[Any, int]] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:40,代码来源:core.py

示例13: __repr__

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def __repr__(self):
    # Axis('x', Dimension(2))
    # TODO(shoyer): make very long reprs more succint?
    return "%s('%s', %r)" % (type(self).__name__, self.name, self.value) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:6,代码来源:core.py

示例14: value

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def value(self):
    """Returns the tf.Dimension or tuple specifying axis ticks."""
    if self.labels is None:
      return self.dimension
    else:
      return self.labels 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:8,代码来源:core.py

示例15: dequeue_many

# 需要导入模块: from tensorflow.python.framework import tensor_shape [as 别名]
# 或者: from tensorflow.python.framework.tensor_shape import Dimension [as 别名]
def dequeue_many(self, n, name=None):
    """Dequeues and concatenates `n` elements from this queue.

    This operation concatenates queue-element component tensors along
    the 0th dimension to make a single component tensor.  All of the
    components in the dequeued tuple will have size `n` in the 0th dimension.

    If the queue is closed and there are less than `n` elements left, then an
    `OutOfRange` exception is raised.

    At runtime, this operation may raise an error if the queue is
    [closed](#QueueBase.close) before or during its execution. If the
    queue is closed, the queue contains fewer than `n` elements, and
    there are no pending enqueue operations that can fulfill this
    request, `tf.errors.OutOfRangeError` will be raised. If the
    session is [closed](../../api_docs/python/client.md#Session.close),
    `tf.errors.CancelledError` will be raised.

    Args:
      n: A scalar `Tensor` containing the number of elements to dequeue.
      name: A name for the operation (optional).

    Returns:
      The tuple of concatenated tensors that was dequeued.
    """
    if name is None:
      name = "%s_DequeueMany" % self._name

    ret = gen_data_flow_ops._queue_dequeue_many_v2(
        self._queue_ref, n=n, component_types=self._dtypes, name=name)

    # NOTE(mrry): Not using a shape function because we need access to
    # the Queue object.
    op = ret[0].op
    batch_dim = tensor_shape.Dimension(tensor_util.constant_value(op.inputs[1]))
    for output, shape in zip(op.values(), self._shapes):
      output.set_shape(tensor_shape.TensorShape([batch_dim]).concatenate(shape))

    return self._dequeue_return_value(ret) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:41,代码来源:data_flow_ops.py


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