| 64 | |
| 65 | template <PoolType pool_type> |
| 66 | TfLiteStatus GenericPrepare(TfLiteContext* context, TfLiteNode* node) { |
| 67 | auto* params = reinterpret_cast<TfLitePoolParams*>(node->builtin_data); |
| 68 | OpData* data = reinterpret_cast<OpData*>(node->user_data); |
| 69 | |
| 70 | TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); |
| 71 | TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); |
| 72 | TfLiteTensor* output = GetOutput(context, node, 0); |
| 73 | const TfLiteTensor* input = GetInput(context, node, 0); |
| 74 | TF_LITE_ENSURE_EQ(context, NumDimensions(input), 4); |
| 75 | TF_LITE_ENSURE_EQ(context, input->type, output->type); |
| 76 | |
| 77 | int batches = input->dims->data[0]; |
| 78 | int height = input->dims->data[1]; |
| 79 | int width = input->dims->data[2]; |
| 80 | int channels_out = input->dims->data[3]; |
| 81 | |
| 82 | // Matching GetWindowedOutputSize in TensorFlow. |
| 83 | auto padding = params->padding; |
| 84 | int out_width, out_height; |
| 85 | |
| 86 | data->padding = ComputePaddingHeightWidth( |
| 87 | params->stride_height, params->stride_width, 1, 1, height, width, |
| 88 | params->filter_height, params->filter_width, padding, &out_height, |
| 89 | &out_width); |
| 90 | |
| 91 | if (input->type == kTfLiteUInt8 || input->type == kTfLiteInt8) { |
| 92 | if (pool_type == kAverage || pool_type == kMax) { |
| 93 | TF_LITE_ENSURE_EQ(context, input->params.scale, output->params.scale); |
| 94 | TF_LITE_ENSURE_EQ(context, input->params.zero_point, |
| 95 | output->params.zero_point); |
| 96 | } |
| 97 | if (pool_type == kL2) { |
| 98 | // We currently don't have a quantized implementation of L2Pool |
| 99 | TF_LITE_ENSURE_EQ(context, input->type, kTfLiteFloat32); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | TfLiteIntArray* output_size = TfLiteIntArrayCreate(4); |
| 104 | output_size->data[0] = batches; |
| 105 | output_size->data[1] = out_height; |
| 106 | output_size->data[2] = out_width; |
| 107 | output_size->data[3] = channels_out; |
| 108 | return context->ResizeTensor(context, output, output_size); |
| 109 | } |
| 110 | |
| 111 | template <KernelType kernel_type> |
| 112 | TfLiteStatus AverageEvalFloat(TfLiteContext* context, TfLiteNode* node, |
nothing calls this directly
no test coverage detected