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) {
|
||||
uint64_t bytes_required = 1;
|
||||
if (!tensor.shape()) {
|
||||
ReportError(error_reporter, "Tensor %s shape is empty",
|
||||
tensor.name()->c_str());
|
||||
return false;
|
||||
// Empty tensor. Avoid further checks.
|
||||
return true;
|
||||
}
|
||||
for (int dim : *tensor.shape()) {
|
||||
bytes_required *= dim;
|
||||
|
@ -148,20 +148,18 @@ TEST(VerifyModel, TestEmptyModel) {
|
||||
::testing::ContainsRegex("Missing 'subgraphs' section."));
|
||||
}
|
||||
|
||||
TEST(VerifyModel, TestEmptyShape) {
|
||||
TEST(VerifyModel, TestEmptyVector) {
|
||||
TfLiteFlatbufferModelBuilder builder({}, {"test"});
|
||||
builder.AddOperator({0, 1}, {3}, BuiltinOperator_CUSTOM, "test");
|
||||
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(
|
||||
{2}, TensorType_STRING,
|
||||
{2, 0, 0, 0, 16, 0, 0, 0, 17, 0, 0, 0, 19, 0, 0, 0, 'A', 'B', 'C'},
|
||||
"data");
|
||||
builder.AddTensor({2, 3}, TensorType_INT32, {}, "output");
|
||||
builder.FinishModel({0, 1}, {3});
|
||||
ASSERT_FALSE(builder.Verify());
|
||||
EXPECT_THAT(builder.GetErrorString(),
|
||||
::testing::ContainsRegex("Tensor inputtwo shape is empty"));
|
||||
ASSERT_TRUE(builder.Verify());
|
||||
}
|
||||
|
||||
TEST(VerifyModel, TestSimpleModel) {
|
||||
|
Loading…
Reference in New Issue
Block a user