Helper class for conducting non_atrous convolution or atrous convolution. Note that this class assumes that shapes of input and filter passed to __call__ are compatible with input_shape and filter_shape passed to the constructor. Note Atrous convolution with 3D convolutions might meet "n
| 145 | |
| 146 | |
| 147 | class _Convolution(object): |
| 148 | """Helper class for conducting non_atrous convolution or atrous convolution. |
| 149 | |
| 150 | Note that this class assumes that shapes of input and filter passed to |
| 151 | __call__ are compatible with input_shape and filter_shape passed to the |
| 152 | constructor. |
| 153 | |
| 154 | Note Atrous convolution with 3D convolutions might meet "no algorithm worked". |
| 155 | |
| 156 | Arguments: |
| 157 | input_shape: static input shape, i.e. input.get_shape(). |
| 158 | filter_shape: static filter shape, i.e. filter.get_shape(). |
| 159 | padding: see _non_atrous_convolution. |
| 160 | data_format: see _non_atrous_convolution. |
| 161 | strides: see _non_atrous_convolution. |
| 162 | dilation_rate: Dilation rate. List of N ints >= 1. N is space dim. Defaults |
| 163 | to [1]*N. |
| 164 | name: see _non_atrous_convolution. |
| 165 | """ |
| 166 | |
| 167 | def __init__( |
| 168 | self, |
| 169 | input_shape, |
| 170 | filter_shape, # pylint: disable=redefined-builtin |
| 171 | padding, |
| 172 | data_format=None, |
| 173 | strides=None, |
| 174 | dilation_rate=None, |
| 175 | name=None): |
| 176 | filter_shape = filter_shape.with_rank(input_shape.ndims) |
| 177 | self.padding = padding |
| 178 | self.name = name |
| 179 | input_shape = input_shape.with_rank(filter_shape.ndims) |
| 180 | if input_shape.ndims is None: |
| 181 | raise ValueError("Rank of convolution must be known") |
| 182 | if input_shape.ndims < 3 or input_shape.ndims > 5: |
| 183 | raise ValueError( |
| 184 | "`input` and `filter` must have rank at least 3 and at most 5") |
| 185 | conv_dims = input_shape.ndims - 2 |
| 186 | if strides is None: |
| 187 | strides = [1] * conv_dims |
| 188 | elif len(strides) != conv_dims: |
| 189 | raise ValueError("len(strides)=%d, but should be %d" % (len(strides), |
| 190 | conv_dims)) |
| 191 | self.dilations = dilation_rate |
| 192 | |
| 193 | if conv_dims == 1: |
| 194 | # conv1d uses the 2-d data format names |
| 195 | if data_format is None: |
| 196 | data_format = "NWC" |
| 197 | elif data_format not in {"NCW", "NWC", "NCHW", "NHWC"}: |
| 198 | raise ValueError("data_format must be \"NWC\" or \"NCW\".") |
| 199 | self.strides = strides[0] |
| 200 | self.data_format = data_format |
| 201 | self.conv_op = self._conv1d |
| 202 | elif conv_dims == 2: |
| 203 | if data_format is None or data_format == "NHWC": |
| 204 | data_format = "NHWC" |
no outgoing calls
no test coverage detected