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

Function ResizeOutputTensor

tensorflow/lite/kernels/batch_to_space_nd.cc:56–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54const int kSpatialDimensionNum = 2;
55
56TfLiteStatus ResizeOutputTensor(TfLiteContext* context,
57 BatchToSpaceNDContext* op_context) {
58 TfLiteIntArray* input_size = op_context->input->dims;
59 const int* block_shape = GetTensorData<int32>(op_context->block_shape);
60 const int* crops = GetTensorData<int32>(op_context->crops);
61
62 TF_LITE_ENSURE_EQ(context, NumDimensions(op_context->block_shape),
63 kBlockSizeDimensionNum);
64 TF_LITE_ENSURE_EQ(context, op_context->block_shape->dims->data[0],
65 kSpatialDimensionNum);
66 TF_LITE_ENSURE_EQ(context, NumDimensions(op_context->crops),
67 kSpatialDimensionNum);
68
69 TF_LITE_ENSURE(context, crops[0] >= 0);
70 TF_LITE_ENSURE(context, crops[1] >= 0);
71 TF_LITE_ENSURE(context, crops[2] >= 0);
72 TF_LITE_ENSURE(context, crops[3] >= 0);
73
74 // Number of batch must be multiple of (block_shape[0] * block_shape[1]).
75 TF_LITE_ENSURE_EQ(context,
76 input_size->data[0] % (block_shape[0] * block_shape[1]), 0);
77
78 const int output_batch_size =
79 input_size->data[0] / (block_shape[0] * block_shape[1]);
80
81 const int crops_top = crops[0];
82 const int crops_bottom = crops[1];
83 const int crops_left = crops[2];
84 const int crops_right = crops[3];
85 const int output_height =
86 input_size->data[1] * block_shape[0] - crops_top - crops_bottom;
87 const int output_width =
88 input_size->data[2] * block_shape[1] - crops_left - crops_right;
89
90 const int output_channel_size = input_size->data[3];
91
92 TfLiteIntArray* output_size = TfLiteIntArrayCopy(input_size);
93 output_size->data[0] = output_batch_size;
94 output_size->data[1] = output_height;
95 output_size->data[2] = output_width;
96 output_size->data[3] = output_channel_size;
97
98 return context->ResizeTensor(context, op_context->output, output_size);
99}
100
101TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
102 TF_LITE_ENSURE_EQ(context, NumInputs(node), 3);

Callers 2

PrepareFunction · 0.70
EvalFunction · 0.70

Calls 3

NumDimensionsFunction · 0.85
TfLiteIntArrayCopyFunction · 0.85
ResizeTensorMethod · 0.80

Tested by

no test coverage detected