| 62 | } |
| 63 | |
| 64 | void ParseSizes(OpKernelContext* context, const std::vector<int32>& strides, |
| 65 | const std::vector<int32>& rates, const Padding& padding, |
| 66 | int* stride_rows, int* stride_cols, int* rate_rows, |
| 67 | int* rate_cols, int64* pad_top, int64* pad_left, |
| 68 | int64* out_rows, int64* out_cols) { |
| 69 | // Input tensor is of the following dimensions: |
| 70 | // [ batch, input_rows, input_cols, depth ] |
| 71 | const Tensor& input = context->input(0); |
| 72 | OP_REQUIRES(context, input.dims() == 4, |
| 73 | errors::InvalidArgument("input must be 4-dimensional", |
| 74 | input.shape().DebugString())); |
| 75 | const int input_rows = input.dim_size(1); |
| 76 | const int input_cols = input.dim_size(2); |
| 77 | const int depth = input.dim_size(3); |
| 78 | |
| 79 | // For now we take the stride and rate from the second and third dimensions |
| 80 | // only (we do not support striding on the batch or depth dimension). |
| 81 | *stride_rows = strides[1]; |
| 82 | *stride_cols = strides[2]; |
| 83 | *rate_rows = rates[1]; |
| 84 | *rate_cols = rates[2]; |
| 85 | |
| 86 | // Input filter is of the following dimensions: |
| 87 | // [ filter_rows, filter_cols, depth ] |
| 88 | const Tensor& filter = context->input(1); |
| 89 | OP_REQUIRES(context, filter.dims() == 3, |
| 90 | errors::InvalidArgument("filter must be 3-dimensional: ", |
| 91 | filter.shape().DebugString())); |
| 92 | const int filter_rows = filter.dim_size(0); |
| 93 | const int filter_cols = filter.dim_size(1); |
| 94 | OP_REQUIRES(context, depth == filter.dim_size(2), |
| 95 | errors::InvalidArgument( |
| 96 | "input and filter must have the same depth: ", depth, " vs ", |
| 97 | filter.dim_size(2))); |
| 98 | |
| 99 | // Effective filter size, after introducing rate - 1 zeros between each |
| 100 | // non-zero filter element. |
| 101 | const int filter_rows_eff = |
| 102 | filter_rows + (filter_rows - 1) * (*rate_rows - 1); |
| 103 | const int filter_cols_eff = |
| 104 | filter_cols + (filter_cols - 1) * (*rate_cols - 1); |
| 105 | |
| 106 | OP_REQUIRES_OK( |
| 107 | context, GetWindowedOutputSize(input_rows, filter_rows_eff, *stride_rows, |
| 108 | padding, out_rows, pad_top)); |
| 109 | OP_REQUIRES_OK( |
| 110 | context, GetWindowedOutputSize(input_cols, filter_cols_eff, *stride_cols, |
| 111 | padding, out_cols, pad_left)); |
| 112 | } |
| 113 | |
| 114 | template <typename Device, typename T> |
| 115 | class DilationOp : public OpKernel { |
no test coverage detected