本文整理匯總了Python中tensorflow.python.framework.tensor_shape.as_dimension方法的典型用法代碼示例。如果您正苦於以下問題:Python tensor_shape.as_dimension方法的具體用法?Python tensor_shape.as_dimension怎麽用?Python tensor_shape.as_dimension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.framework.tensor_shape
的用法示例。
在下文中一共展示了tensor_shape.as_dimension方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_conv_output_size
# 需要導入模塊: from tensorflow.python.framework import tensor_shape [as 別名]
# 或者: from tensorflow.python.framework.tensor_shape import as_dimension [as 別名]
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)
示例2: testAsDimension
# 需要導入模塊: from tensorflow.python.framework import tensor_shape [as 別名]
# 或者: from tensorflow.python.framework.tensor_shape import as_dimension [as 別名]
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)
示例3: get2d_deconv_output_size
# 需要導入模塊: from tensorflow.python.framework import tensor_shape [as 別名]
# 或者: from tensorflow.python.framework.tensor_shape import as_dimension [as 別名]
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
示例4: get2d_deconv_output_size
# 需要導入模塊: from tensorflow.python.framework import tensor_shape [as 別名]
# 或者: from tensorflow.python.framework.tensor_shape import as_dimension [as 別名]
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