(self, input_shape)
| 2024 | return [math_ops.cast(pass_through_if, grad.dtype) * grad, None] |
| 2025 | |
| 2026 | def build(self, input_shape): |
| 2027 | channel_axis = self._channel_axis() |
| 2028 | input_shape = tensor_shape.TensorShape(input_shape) |
| 2029 | num_channels = input_shape.dims[channel_axis].value |
| 2030 | if num_channels is None: |
| 2031 | raise ValueError('The channel dimension of the inputs to `GDN` ' |
| 2032 | 'must be defined.') |
| 2033 | self._input_rank = input_shape.ndims |
| 2034 | self.input_spec = input_spec.InputSpec( |
| 2035 | ndim=input_shape.ndims, axes={channel_axis: num_channels}) |
| 2036 | |
| 2037 | pedestal = array_ops.constant(self._reparam_offset**2, dtype=self.dtype) |
| 2038 | beta_bound = array_ops.constant( |
| 2039 | (self._beta_min + self._reparam_offset**2)**.5, dtype=self.dtype) |
| 2040 | gamma_bound = array_ops.constant(self._reparam_offset, dtype=self.dtype) |
| 2041 | |
| 2042 | def beta_initializer(shape, dtype=None, partition_info=None): |
| 2043 | del partition_info # unused |
| 2044 | pedestal = array_ops.constant(self._reparam_offset**2, dtype=self.dtype) |
| 2045 | return math_ops.sqrt(array_ops.ones(shape, dtype=dtype) + pedestal) |
| 2046 | |
| 2047 | def gamma_initializer(shape, dtype=None, partition_info=None): |
| 2048 | del partition_info # unused |
| 2049 | assert len(shape) == 2 |
| 2050 | assert shape[0] == shape[1] |
| 2051 | eye = linalg_ops.eye(shape[0], dtype=dtype) |
| 2052 | pedestal = array_ops.constant(self._reparam_offset**2, dtype=self.dtype) |
| 2053 | return math_ops.sqrt(self._gamma_init * eye + pedestal) |
| 2054 | |
| 2055 | beta = self.add_variable( |
| 2056 | 'reparam_beta', |
| 2057 | shape=[num_channels], |
| 2058 | initializer=beta_initializer, |
| 2059 | dtype=self.dtype, |
| 2060 | trainable=True) |
| 2061 | beta = self._lower_bound(beta, beta_bound) |
| 2062 | self.beta = math_ops.square(beta) - pedestal |
| 2063 | |
| 2064 | gamma = self.add_variable( |
| 2065 | 'reparam_gamma', |
| 2066 | shape=[num_channels, num_channels], |
| 2067 | initializer=gamma_initializer, |
| 2068 | dtype=self.dtype, |
| 2069 | trainable=True) |
| 2070 | gamma = self._lower_bound(gamma, gamma_bound) |
| 2071 | self.gamma = math_ops.square(gamma) - pedestal |
| 2072 | |
| 2073 | self.built = True |
| 2074 | |
| 2075 | def call(self, inputs): |
| 2076 | inputs = ops.convert_to_tensor(inputs, dtype=self.dtype) |
nothing calls this directly
no test coverage detected