Shape function for a Conv2D op. This op has two inputs: * input, a 4D tensor with shape = [batch_size, rows, cols, depth_in] * filter, a 4D tensor with shape = [filter_rows, filter_cols, depth_in, depth_out] The output is a 4D tensor with shape = [batch_size, out_rows, out_cols, de
(op)
| 166 | |
| 167 | |
| 168 | def conv2d_shape(op): |
| 169 | """Shape function for a Conv2D op. |
| 170 | |
| 171 | This op has two inputs: |
| 172 | |
| 173 | * input, a 4D tensor with shape = [batch_size, rows, cols, depth_in] |
| 174 | * filter, a 4D tensor with shape = [filter_rows, filter_cols, |
| 175 | depth_in, depth_out] |
| 176 | |
| 177 | The output is a 4D tensor with shape = [batch_size, out_rows, |
| 178 | out_cols, depth_out], where out_rows and out_cols depend on the |
| 179 | value of the op's "padding" and "strides" attrs. |
| 180 | |
| 181 | Args: |
| 182 | op: A Conv2D Operation. |
| 183 | |
| 184 | Returns: |
| 185 | A list containing the Shape of the Conv2D output. |
| 186 | |
| 187 | Raises: |
| 188 | ValueError: If the shapes of the input or filter are incompatible. |
| 189 | """ |
| 190 | input_shape = op.inputs[0].get_shape().with_rank(4) |
| 191 | filter_shape = op.inputs[1].get_shape().with_rank(4) |
| 192 | |
| 193 | try: |
| 194 | data_format = op.get_attr("data_format") |
| 195 | except ValueError: |
| 196 | data_format = None |
| 197 | |
| 198 | if data_format == b"NCHW": |
| 199 | # Convert input shape to the default NHWC for inference. |
| 200 | input_shape = [input_shape[0], input_shape[2], input_shape[3], |
| 201 | input_shape[1]] |
| 202 | |
| 203 | batch_size = input_shape[0] |
| 204 | in_rows = input_shape[1] |
| 205 | in_cols = input_shape[2] |
| 206 | |
| 207 | filter_rows = filter_shape[0] |
| 208 | filter_cols = filter_shape[1] |
| 209 | depth_out = filter_shape[3] |
| 210 | # Check that the input depths are compatible. |
| 211 | input_shape[3].assert_is_compatible_with(filter_shape[2]) |
| 212 | |
| 213 | if data_format == b"NCHW": |
| 214 | stride_b, stride_d, stride_r, stride_c = op.get_attr("strides") |
| 215 | else: |
| 216 | stride_b, stride_r, stride_c, stride_d = op.get_attr("strides") |
| 217 | |
| 218 | if stride_b != 1 or stride_d != 1: |
| 219 | raise ValueError("Current implementation does not yet support " |
| 220 | "strides in the batch and depth dimensions.") |
| 221 | # TODO(mrry,shlens): Raise an error if the stride would cause |
| 222 | # information in the input to be ignored. This will require a change |
| 223 | # in the kernel implementation. |
| 224 | padding = op.get_attr("padding") |
| 225 | out_rows, out_cols = get2d_conv_output_size(in_rows, in_cols, filter_rows, |
nothing calls this directly
no test coverage detected