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


Python tensor_shape.as_dimension函数代码示例

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


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

示例1: get2d_deconv_output_size

def get2d_deconv_output_size(input_height, input_width, filter_height,
                           filter_width, row_stride, col_stride, padding_type):
    """Returns the number of rows and columns in a convolution/pooling output."""
    input_height = tensor_shape.as_dimension(input_height)
    input_width = tensor_shape.as_dimension(input_width)
    filter_height = tensor_shape.as_dimension(filter_height)
    filter_width = tensor_shape.as_dimension(filter_width)
    row_stride = int(row_stride)
    col_stride = int(col_stride)

    # Compute number of rows in the output, based on the padding.
    if input_height.value is None or filter_height.value is None:
      out_rows = None
    elif padding_type == "VALID":
      out_rows = (input_height.value - 1) * row_stride + filter_height.value
    elif padding_type == "SAME":
      out_rows = input_height.value * row_stride
    else:
      raise ValueError("Invalid value for padding: %r" % padding_type)

    # Compute number of columns in the output, based on the padding.
    if input_width.value is None or filter_width.value is None:
      out_cols = None
    elif padding_type == "VALID":
      out_cols = (input_width.value - 1) * col_stride + filter_width.value
    elif padding_type == "SAME":
      out_cols = input_width.value * col_stride

    return out_rows, out_cols
开发者ID:313-Ventures,项目名称:edward,代码行数:29,代码来源:convolutional_vae_util.py

示例2: testAsDimension

 def testAsDimension(self):
     self.assertEqual(tensor_shape.Dimension(12), tensor_shape.as_dimension(tensor_shape.Dimension(12)))
     self.assertEqual(tensor_shape.Dimension(12), tensor_shape.as_dimension(12))
     self.assertEqual(
         tensor_shape.Dimension(None).value, tensor_shape.as_dimension(tensor_shape.Dimension(None)).value
     )
     self.assertEqual(tensor_shape.Dimension(None).value, tensor_shape.as_dimension(None).value)
开发者ID:peace195,项目名称:tensorflow,代码行数:7,代码来源:tensor_shape_test.py

示例3: _Get2DOutputSize

def _Get2DOutputSize(input_height, input_width, filter_height, filter_width,
                     row_stride, col_stride, padding_type):
  """Returns the number of rows and columns in a convolution/pooling output."""
  input_height = tensor_shape.as_dimension(input_height)
  input_width = tensor_shape.as_dimension(input_width)
  filter_height = tensor_shape.as_dimension(filter_height)
  filter_width = tensor_shape.as_dimension(filter_width)
  row_stride = int(row_stride)
  col_stride = int(col_stride)

  if filter_height.value == 1 and filter_width.value == 1 and (
      row_stride == 1 and col_stride == 1):
    return input_height, input_width
  else:
    if filter_height > input_height or filter_width > input_width:
      raise ValueError("filter must not be larger than the input: ",
                       "Filter: [", filter_height, "x", filter_width, "] ",
                       "Input: [", input_height, "x", input_width, "] ")
    if row_stride > filter_height or col_stride > filter_width:
      raise ValueError("stride must be less than or equal to filter size",
                       "stride: [", row_stride, "x", col_stride, "] ",
                       "filter: [", filter_height, "x", filter_width, "] ")

    # Compute number of rows in the output, based on the padding.
    if input_height.value is None or filter_height.value is None:
      out_rows = None
    elif padding_type == "VALID":
      out_rows = int(
          math.ceil((input_height.value - filter_height.value + 1.0)
                    / row_stride))
    elif padding_type == "SAME":
      out_rows = int(math.ceil(input_height.value * 1.0
                               / row_stride))
    else:
      raise ValueError("Invalid value for padding: %r" % padding_type)

    # Compute number of columns in the output, based on the padding.
    if input_width.value is None or filter_width.value is None:
      out_cols = None
    elif padding_type == "VALID":
      out_cols = int(
          math.ceil((input_width.value - filter_width.value + 1.0)
                    / col_stride))
    elif padding_type == "SAME":
      out_cols = int(math.ceil(input_width.value * 1.0 / col_stride))

    return out_rows, out_cols
开发者ID:bradg19,项目名称:tensor,代码行数:47,代码来源:common_shapes.py

示例4: get2d_conv_output_size

def get2d_conv_output_size(input_height, input_width, filter_height,
                           filter_width, row_stride, col_stride, padding_type):
  """Returns the number of rows and columns in a convolution/pooling output."""
  input_height = tensor_shape.as_dimension(input_height)
  input_width = tensor_shape.as_dimension(input_width)
  filter_height = tensor_shape.as_dimension(filter_height)
  filter_width = tensor_shape.as_dimension(filter_width)
  row_stride = int(row_stride)
  col_stride = int(col_stride)

  if filter_height.value == 1 and filter_width.value == 1 and (
      row_stride == 1 and col_stride == 1):
    return input_height, input_width
  else:
    if filter_height > input_height or filter_width > input_width:
      raise ValueError(
          "filter must not be larger than the input: "
          "Filter: [%sx%s] Input: [%sx%s]"
          % (filter_height, filter_width, input_height, input_width))
    if row_stride > filter_height or col_stride > filter_width:
      raise ValueError("stride must be less than or equal to filter size",
                       "stride: [%sx%s] filter: [%sx%s]"
                       % (row_stride, col_stride, filter_height, filter_width))

    # Compute number of rows in the output, based on the padding.
    if input_height.value is None or filter_height.value is None:
      out_rows = None
    elif padding_type == b"VALID":
      out_rows = ((input_height.value - filter_height.value + row_stride) //
                  row_stride)
    elif padding_type == b"SAME":
      out_rows = (input_height.value + row_stride - 1) // row_stride
    else:
      raise ValueError("Invalid value for padding: %r" % padding_type)

    # Compute number of columns in the output, based on the padding.
    if input_width.value is None or filter_width.value is None:
      out_cols = None
    elif padding_type == b"VALID":
      out_cols = ((input_width.value - filter_width.value + col_stride) //
                  col_stride)
    elif padding_type == b"SAME":
      out_cols = (input_width.value + col_stride - 1) // col_stride

    return out_rows, out_cols
开发者ID:13683116633,项目名称:tensorflow,代码行数:45,代码来源:common_shapes.py

示例5: _cudnn_rnn_forward_shape

def _cudnn_rnn_forward_shape(op):
    """Shape function for the CudnnRNN forward operation.

  Args:
    op: the forward op.
  Returns:
    A list of shapes for the forward operation.
  """
    input_shape = op.inputs[0].get_shape()
    input_h_shape = op.inputs[1].get_shape()
    seq_length = input_shape[0]
    batch_size = input_shape[1]
    num_units = input_h_shape[2]
    direction = op.get_attr("direction")
    rnn_mode = op.get_attr("rnn_mode")
    dir_count = tensor_shape.as_dimension(2) if direction == "bidirectional" else tensor_shape.as_dimension(1)
    output_shape = [seq_length, batch_size, dir_count * num_units]
    output_h_shape = input_h_shape
    output_c_shape = output_h_shape if rnn_mode == "lstm" else []
    return [output_shape, output_h_shape, output_c_shape, None]
开发者ID:yxiong,项目名称:tensorflow,代码行数:20,代码来源:cudnn_rnn_ops.py

示例6: get_conv_output_size

def get_conv_output_size(input_size, filter_size, strides, padding_type):
  """Returns the spatial size of a n-d convolution/pooling output."""
  input_size = tuple([tensor_shape.as_dimension(x).value for x in input_size])
  filter_size = tuple([tensor_shape.as_dimension(x).value for x in filter_size])
  strides = [int(x) for x in strides]

  if all(x == 1 for x in input_size) and all(x == 1 for x in filter_size):
    return input_size

  if any(x is not None and y is not None and x > y for x, y in
         zip(filter_size, input_size)):
    raise ValueError("Filter must not be larger than the input: "
                     "Filter: %r Input: %r" % (filter_size, input_size))

  if padding_type == b"VALID":

    def _valid(in_dim, k_dim, s_dim):
      if in_dim is not None and k_dim is not None:
        return (in_dim - k_dim + s_dim) // s_dim
      else:
        return None

    output_size = [
        _valid(in_dim, k_dim, s_dim)
        for in_dim, k_dim, s_dim in zip(input_size, filter_size, strides)
    ]
  elif padding_type == b"SAME":

    def _same(in_dim, s_dim):
      if in_dim is not None:
        return (in_dim + s_dim - 1) // s_dim
      else:
        return None

    output_size = [_same(in_dim, s_dim)
                   for in_dim, s_dim in zip(input_size, strides)]
  else:
    raise ValueError("Invalid padding: %r" % padding_type)

  return tuple(output_size)
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:40,代码来源:common_shapes.py

示例7: get_static_batch_size

def get_static_batch_size(layer):
  """Gets the static batch size of a Layer.

  Arguments:
    layer: a `Layer` instance.

  Returns:
    The static batch size of a Layer.
  """
  batch_input_shape, _ = get_input_shape_and_dtype(layer)
  if batch_input_shape is not None:
    return tensor_shape.as_dimension(batch_input_shape[0]).value
  return None
开发者ID:aeverall,项目名称:tensorflow,代码行数:13,代码来源:training_utils.py

示例8: set_shard_dimension

  def set_shard_dimension(self, shard_dimension):
    """Sets the shard dimension for the current policy.

    If the policy has been frozen then shard_dimension must match the
    existing setting.

    Args:
      shard_dimension: The shard dimension to use in the policy.

    Raises:
      ValueError: If the policy has been frozen and shard_dimension
        differs from the frozen value, or shard_dimension can't be
        interpreted as a Dimension.
    """
    if self._frozen:
      if self._shard_dimension != shard_dimension:
        raise ValueError(
            "Can't set shard dimension to %d since it has been frozen to "
            "use %d." % (shard_dimension, self._shard_dimension))
    else:
      self._shard_dimension = tensor_shape.as_dimension(shard_dimension)
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:21,代码来源:tpu_sharding.py

示例9: _is_shape_component

 def _is_shape_component(element):
   value = tensor_shape.as_dimension(element).value
   return value is None or isinstance(value, int)
开发者ID:kylin9872,项目名称:tensorflow,代码行数:3,代码来源:tf_utils.py

示例10: _fill_default_values

 def _fill_default_values(self):
   if self._number_of_shards is None:
     self._number_of_shards = _DEFAULT_NUMBER_OF_SHARDS
   if self._shard_dimension is None:
     self._shard_dimension = tensor_shape.as_dimension(
         _DEFAULT_SHARD_DIMENSION)
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:6,代码来源:tpu_sharding.py


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