Python tensorflow.python.framework.tensor_shape.as_dimension() Examples
The following are 8
code examples of tensorflow.python.framework.tensor_shape.as_dimension().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.python.framework.tensor_shape
, or try the search function
.
Example #1
Source File: common_shapes.py From lambda-packs with MIT License | 5 votes |
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)
Example #2
Source File: common_shapes.py From auto-alt-text-lambda-api with MIT License | 5 votes |
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)
Example #3
Source File: tensor_shape_test.py From deep_image_model with Apache License 2.0 | 5 votes |
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)
Example #4
Source File: common_shapes.py From deep_image_model with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: deconv.py From lmdis-rep with Apache License 2.0 | 5 votes |
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
Example #6
Source File: convolutional_vae_util.py From CVAE with MIT License | 5 votes |
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
Example #7
Source File: common_shapes.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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)
Example #8
Source File: common_shapes.py From keras-lambda with MIT License | 5 votes |
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)