Python tensorflow.python.ops.nn.pool() Examples
The following are 2
code examples of tensorflow.python.ops.nn.pool().
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.ops.nn
, or try the search function
.
Example #1
Source File: layers.py From tensornets with MIT License | 5 votes |
def call(self, inputs): inputs = ops.convert_to_tensor(inputs, dtype=self.dtype) ndim = self._input_rank shape = self.gamma.get_shape().as_list() gamma = array_ops.reshape(self.gamma, (ndim - 2) * [1] + shape) # Compute normalization pool. if self.data_format == 'channels_first': norm_pool = nn.convolution( math_ops.square(inputs), gamma, 'VALID', data_format='NC' + 'DHW' [-(ndim - 2):]) if ndim == 3: norm_pool = array_ops.expand_dims(norm_pool, 2) norm_pool = nn.bias_add(norm_pool, self.beta, data_format='NCHW') norm_pool = array_ops.squeeze(norm_pool, [2]) elif ndim == 5: shape = array_ops.shape(norm_pool) norm_pool = array_ops.reshape(norm_pool, shape[:3] + [-1]) norm_pool = nn.bias_add(norm_pool, self.beta, data_format='NCHW') norm_pool = array_ops.reshape(norm_pool, shape) else: # ndim == 4 norm_pool = nn.bias_add(norm_pool, self.beta, data_format='NCHW') else: # channels_last norm_pool = nn.convolution(math_ops.square(inputs), gamma, 'VALID') norm_pool = nn.bias_add(norm_pool, self.beta, data_format='NHWC') norm_pool = math_ops.sqrt(norm_pool) if self.inverse: outputs = inputs * norm_pool else: outputs = inputs / norm_pool outputs.set_shape(inputs.get_shape()) return outputs
Example #2
Source File: layers.py From tf-slim with Apache License 2.0 | 5 votes |
def call(self, inputs): inputs = ops.convert_to_tensor(inputs, dtype=self.dtype) ndim = self._input_rank shape = self.gamma.get_shape().as_list() gamma = array_ops.reshape(self.gamma, (ndim - 2) * [1] + shape) # Compute normalization pool. if self.data_format == 'channels_first': norm_pool = nn.convolution( math_ops.square(inputs), gamma, 'VALID', data_format='NC' + 'DHW' [-(ndim - 2):]) if ndim == 3: norm_pool = array_ops.expand_dims(norm_pool, 2) norm_pool = nn.bias_add(norm_pool, self.beta, data_format='NCHW') norm_pool = array_ops.squeeze(norm_pool, [2]) elif ndim == 5: shape = array_ops.shape(norm_pool) norm_pool = array_ops.reshape(norm_pool, shape[:3] + [-1]) norm_pool = nn.bias_add(norm_pool, self.beta, data_format='NCHW') norm_pool = array_ops.reshape(norm_pool, shape) else: # ndim == 4 norm_pool = nn.bias_add(norm_pool, self.beta, data_format='NCHW') else: # channels_last norm_pool = nn.convolution(math_ops.square(inputs), gamma, 'VALID') norm_pool = nn.bias_add(norm_pool, self.beta, data_format='NHWC') norm_pool = math_ops.sqrt(norm_pool) if self.inverse: outputs = inputs * norm_pool else: outputs = inputs / norm_pool outputs.set_shape(inputs.get_shape()) return outputs