diff options
author | 2017-12-07 11:29:51 -0800 | |
---|---|---|
committer | 2017-12-07 11:36:10 -0800 | |
commit | 1fe793d36a2907ab063bc508fab264cf9e2c46db (patch) | |
tree | 77786f36914da8775ce5a2e24d3aaa788d7cd6b6 /tensorflow/contrib/lite/model_test.cc | |
parent | 1e54177c916d97c34faa1a349b9898186f8b6325 (diff) |
Adds support for loading model directly from a Flatbuffer object.
PiperOrigin-RevId: 178270704
Diffstat (limited to 'tensorflow/contrib/lite/model_test.cc')
-rw-r--r-- | tensorflow/contrib/lite/model_test.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tensorflow/contrib/lite/model_test.cc b/tensorflow/contrib/lite/model_test.cc index 83a5150a46..5330c8f594 100644 --- a/tensorflow/contrib/lite/model_test.cc +++ b/tensorflow/contrib/lite/model_test.cc @@ -255,6 +255,28 @@ TEST(BasicFlatBufferModel, TestBuildModelFromCorruptedData) { ASSERT_FALSE(model); } +// Test that loading model directly from a Model flatbuffer works. +TEST(BasicFlatBufferModel, TestBuildFromModel) { + TestErrorReporter reporter; + FileCopyAllocation model_allocation( + "tensorflow/contrib/lite/testdata/test_model.bin", &reporter); + ASSERT_TRUE(model_allocation.valid()); + ::flatbuffers::Verifier verifier( + reinterpret_cast<const uint8_t*>(model_allocation.base()), + model_allocation.bytes()); + ASSERT_TRUE(VerifyModelBuffer(verifier)); + const Model* model_fb = ::tflite::GetModel(model_allocation.base()); + + auto model = FlatBufferModel::BuildFromModel(model_fb); + ASSERT_TRUE(model); + + std::unique_ptr<Interpreter> interpreter; + ASSERT_EQ( + InterpreterBuilder(*model, TrivialResolver(&dummy_reg))(&interpreter), + kTfLiteOk); + ASSERT_NE(interpreter, nullptr); +} + // TODO(aselle): Add tests for serialization of builtin op data types. // These tests will occur with the evaluation tests of individual operators, // not here. |