MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GenericPrepare

Function GenericPrepare

tensorflow/lite/kernels/pooling.cc:66–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64
65template <PoolType pool_type>
66TfLiteStatus 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
111template <KernelType kernel_type>
112TfLiteStatus AverageEvalFloat(TfLiteContext* context, TfLiteNode* node,

Callers

nothing calls this directly

Calls 8

NumInputsFunction · 0.85
GetOutputFunction · 0.85
GetInputFunction · 0.85
NumDimensionsFunction · 0.85
TfLiteIntArrayCreateFunction · 0.85
ResizeTensorMethod · 0.80
NumOutputsFunction · 0.70

Tested by

no test coverage detected