Skip to content

Commit 1204ded

Browse files
committed
Use consistent const-tensor checks
@tensorflow/micro Use consistent const-tensor checks and error messages across these kernels: PAD RESIZE_BILINEAR RESIZE_NEAREST_NEIGHBOR SPLIT_V SPLIT bug=fixes #3138
1 parent f50a6ea commit 1204ded

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

tensorflow/lite/micro/kernels/pad_common.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ TfLiteStatus PadPrepare(TfLiteContext* context, TfLiteNode* node) {
6969
// On Micro, outputs must be properly sized by the converter.
7070
// NOTE: This data is only available because the paddings buffer is stored in
7171
// the flatbuffer:
72-
TF_LITE_ENSURE(context, IsConstantTensor(paddings));
72+
TF_LITE_ENSURE_MSG(context, IsConstantTensor(paddings),
73+
"Non-constant >paddings< tensor is not supported");
7374
const int32_t* paddings_data = GetTensorData<int32_t>(paddings);
7475
for (int i = 0; i < output->dims->size; i++) {
7576
int output_dim = output->dims->data[i];

tensorflow/lite/micro/kernels/resize_bilinear.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2025 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ TfLiteStatus ResizeBilinearPrepare(TfLiteContext* context, TfLiteNode* node) {
5050
output->type = input->type;
5151

5252
TF_LITE_ENSURE_MSG(context, IsConstantTensor(size),
53-
"Non constant size tensor not supported");
53+
"Non-constant >size< tensor is not supported");
5454

5555
// Ensure params are valid.
5656
auto* params =

tensorflow/lite/micro/kernels/resize_nearest_neighbor.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2025 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -54,10 +54,8 @@ TfLiteStatus ResizeNearestNeighborPrepare(TfLiteContext* context,
5454

5555
output->type = input->type;
5656

57-
if (!IsConstantTensor(size)) {
58-
MicroPrintf("Dynamic tensors are unsupported in tfmicro.");
59-
return kTfLiteError;
60-
}
57+
TF_LITE_ENSURE_MSG(context, IsConstantTensor(size),
58+
"Non-constant >size< tensor is not supported");
6159

6260
micro_context->DeallocateTempTfLiteTensor(input);
6361
micro_context->DeallocateTempTfLiteTensor(size);

tensorflow/lite/micro/kernels/split.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2025 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@ TfLiteStatus SplitPrepare(TfLiteContext* context, TfLiteNode* node) {
7676
// But Micro doesn't support dynamic memory allocation, so we only support
7777
// constant axis tensor for now.
7878
TF_LITE_ENSURE_MSG(context, IsConstantTensor(axis),
79-
"Non constant axis tensor not supported");
79+
"Non-constant >axis< tensor is not supported");
8080

8181
micro_context->DeallocateTempTfLiteTensor(axis);
8282
return kTfLiteOk;

tensorflow/lite/micro/kernels/split_v.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2025 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -80,7 +80,7 @@ TfLiteStatus SplitVPrepare(TfLiteContext* context, TfLiteNode* node) {
8080
// constant axis tensor for now.
8181
TfLiteTensor* axis = micro_context->AllocateTempInputTensor(node, 2);
8282
TF_LITE_ENSURE_MSG(context, IsConstantTensor(axis),
83-
"Non constant axis tensor not supported");
83+
"Non-constant >axis< tensor is not supported");
8484
micro_context->DeallocateTempTfLiteTensor(axis);
8585
return kTfLiteOk;
8686
}

tensorflow/lite/micro/kernels/xtensa/pad.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2025 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -91,7 +91,8 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
9191
// On Micro, outputs must be properly sized by the converter.
9292
// NOTE: This data is only available because the paddings buffer is stored in
9393
// the flatbuffer:
94-
TF_LITE_ENSURE(context, IsConstantTensor(paddings));
94+
TF_LITE_ENSURE_MSG(context, IsConstantTensor(paddings),
95+
"Non-constant >paddings< tensor is not supported");
9596
const int32_t* paddings_data = GetTensorData<int32_t>(paddings);
9697
for (int i = 0; i < output->dims->size; i++) {
9798
int output_dim = output->dims->data[i];

0 commit comments

Comments
 (0)