Allow empty vectors in tflite::Verify
PiperOrigin-RevId: 234886466
This commit is contained in:
parent
6513629c35
commit
69ab50a9b6
@ -110,9 +110,8 @@ bool VerifyNumericTensorBuffer(const Tensor& tensor, const Buffer& buffer,
|
|||||||
ErrorReporter* error_reporter) {
|
ErrorReporter* error_reporter) {
|
||||||
uint64_t bytes_required = 1;
|
uint64_t bytes_required = 1;
|
||||||
if (!tensor.shape()) {
|
if (!tensor.shape()) {
|
||||||
ReportError(error_reporter, "Tensor %s shape is empty",
|
// Empty tensor. Avoid further checks.
|
||||||
tensor.name()->c_str());
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
for (int dim : *tensor.shape()) {
|
for (int dim : *tensor.shape()) {
|
||||||
bytes_required *= dim;
|
bytes_required *= dim;
|
||||||
|
@ -148,20 +148,18 @@ TEST(VerifyModel, TestEmptyModel) {
|
|||||||
::testing::ContainsRegex("Missing 'subgraphs' section."));
|
::testing::ContainsRegex("Missing 'subgraphs' section."));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VerifyModel, TestEmptyShape) {
|
TEST(VerifyModel, TestEmptyVector) {
|
||||||
TfLiteFlatbufferModelBuilder builder({}, {"test"});
|
TfLiteFlatbufferModelBuilder builder({}, {"test"});
|
||||||
builder.AddOperator({0, 1}, {3}, BuiltinOperator_CUSTOM, "test");
|
builder.AddOperator({0, 1}, {3}, BuiltinOperator_CUSTOM, "test");
|
||||||
builder.AddTensor({2, 3}, TensorType_UINT8, {1, 2, 3, 4, 5, 6}, "input");
|
builder.AddTensor({2, 3}, TensorType_UINT8, {1, 2, 3, 4, 5, 6}, "input");
|
||||||
builder.AddTensor({}, TensorType_UINT8, {1, 2, 3, 4, 5, 6}, "inputtwo");
|
builder.AddTensor({}, TensorType_UINT8, {}, "empty_vector");
|
||||||
builder.AddTensor(
|
builder.AddTensor(
|
||||||
{2}, TensorType_STRING,
|
{2}, TensorType_STRING,
|
||||||
{2, 0, 0, 0, 16, 0, 0, 0, 17, 0, 0, 0, 19, 0, 0, 0, 'A', 'B', 'C'},
|
{2, 0, 0, 0, 16, 0, 0, 0, 17, 0, 0, 0, 19, 0, 0, 0, 'A', 'B', 'C'},
|
||||||
"data");
|
"data");
|
||||||
builder.AddTensor({2, 3}, TensorType_INT32, {}, "output");
|
builder.AddTensor({2, 3}, TensorType_INT32, {}, "output");
|
||||||
builder.FinishModel({0, 1}, {3});
|
builder.FinishModel({0, 1}, {3});
|
||||||
ASSERT_FALSE(builder.Verify());
|
ASSERT_TRUE(builder.Verify());
|
||||||
EXPECT_THAT(builder.GetErrorString(),
|
|
||||||
::testing::ContainsRegex("Tensor inputtwo shape is empty"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VerifyModel, TestSimpleModel) {
|
TEST(VerifyModel, TestSimpleModel) {
|
||||||
|
Loading…
Reference in New Issue
Block a user