Merge pull request #26640 from joyalbin:add_dynamic_pad_test

PiperOrigin-RevId: 238723763
This commit is contained in:
TensorFlower Gardener 2019-03-15 15:46:04 -07:00
commit fed677e9dd
3 changed files with 22 additions and 2 deletions

View File

@ -1369,9 +1369,10 @@ cc_test(
size = "small",
srcs = ["subgraph_test_util_test.cc"],
deps = [
":kernel_util",
":subgraph_test_util",
":test_util",
"//tensorflow/lite:framework",
"//tensorflow/lite/kernels:test_util",
"@com_google_googletest//:gtest",
],
)

View File

@ -27,9 +27,11 @@ namespace tflite {
namespace ops {
namespace builtin {
// ADD and MUL are used to test simple branch.
// ADD and MUL can be used to test dynamic sized subgraphs with the
// use of IF op.
TfLiteRegistration* Register_ADD();
TfLiteRegistration* Register_MUL();
// ADD and MUL are used to test dynamic sized subgraphs.
// PAD is used to test dynamic sized subgraphs.
TfLiteRegistration* Register_PAD();
TfLiteRegistration* Register_LESS_EQUAL();
} // namespace builtin

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/lite/kernels/subgraph_test_util.h"
#include <gtest/gtest.h>
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/kernel_util.h"
#include "tensorflow/lite/kernels/test_util.h"
namespace tflite {
@ -106,6 +107,22 @@ TEST_F(SubgraphBuilderTest, TestBuildPadSubgraph) {
CheckIntTensor(output, {5}, {0, 5, 7, 0, 0});
}
TEST_F(SubgraphBuilderTest, TestBuildDynamicPadSubgraph) {
builder_->BuildPadSubgraph(&interpreter_->primary_subgraph());
interpreter_->ResizeInputTensor(interpreter_->inputs()[0], {2});
interpreter_->ResizeInputTensor(interpreter_->inputs()[1], {1, 2});
ASSERT_EQ(interpreter_->AllocateTensors(), kTfLiteOk);
FillIntTensor(interpreter_->tensor(interpreter_->inputs()[0]), {5, 7});
FillIntTensor(interpreter_->tensor(interpreter_->inputs()[1]), {1, 2});
ASSERT_EQ(interpreter_->Invoke(), kTfLiteOk);
TfLiteTensor* output = interpreter_->tensor(interpreter_->outputs()[0]);
EXPECT_TRUE(IsDynamicTensor(output));
CheckIntTensor(output, {5}, {0, 5, 7, 0, 0});
}
TEST_F(SubgraphBuilderTest, TestBuildLessEqualCondSubgraph) {
builder_->BuildLessEqualCondSubgraph(&interpreter_->primary_subgraph(), 3);