Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load TfLite models correctly for s390x #2200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Status LoadTfLiteModel(const string& model_dir, SavedModelBundle* bundle,
model_bytes.resize(size);
absl::string_view sv;
TF_RETURN_IF_ERROR(file->Read(0, size, &sv, &model_bytes[0]));
#if FLATBUFFERS_LITTLEENDIAN == 0
tflite::FlatBufferModel::ByteSwapSerializedModel(&model_bytes, false);
#endif

std::unique_ptr<TfLiteSession> tflite_session;
TF_RETURN_IF_ERROR(TfLiteSession::Create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ TEST(TfLiteInterpreterPool, CreateTfLiteInterpreterPoolTest) {
TF_ASSERT_OK(ReadFileToString(Env::Default(),
test_util::TestSrcDirPath(kParseExampleModel),
&model_bytes));
#if FLATBUFFERS_LITTLEENDIAN == 0
tflite::FlatBufferModel::ByteSwapSerializedModel(&model_bytes, false);
#endif
auto model = tflite::FlatBufferModel::BuildFromModel(
flatbuffers::GetRoot<tflite::Model>(model_bytes.data()));
int pool_size = 1;
Expand Down Expand Up @@ -102,6 +105,9 @@ TEST(TfLiteInterpreterWrapper, TfLiteInterpreterWrapperTest) {
TF_ASSERT_OK(ReadFileToString(Env::Default(),
test_util::TestSrcDirPath(kParseExampleModel),
&model_bytes));
#if FLATBUFFERS_LITTLEENDIAN == 0
tflite::FlatBufferModel::ByteSwapSerializedModel(&model_bytes, false);
#endif
auto model = tflite::FlatBufferModel::BuildFromModel(
flatbuffers::GetRoot<tflite::Model>(model_bytes.data()));
tflite::ops::builtin::BuiltinOpResolver resolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ int main(int argc, char** argv) {
std::string model_bytes;
auto status =
ReadFileToString(tensorflow::Env::Default(), filename, &model_bytes);
#if FLATBUFFERS_LITTLEENDIAN == 0
tflite::FlatBufferModel::ByteSwapSerializedModel(&model_bytes, false);
#endif
if (!status.ok()) {
std::cerr << "ERROR: Failed to read model file: " << filename
<< " with error: " << status << std::endl;
Expand Down
15 changes: 15 additions & 0 deletions tensorflow_serving/servables/tensorflow/tflite_session_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ TEST(TfLiteSession, BasicTest) {
TF_ASSERT_OK(ReadFileToString(tensorflow::Env::Default(),
test_util::TestSrcDirPath(kTestModel),
&model_bytes));
#if FLATBUFFERS_LITTLEENDIAN == 0
tflite::FlatBufferModel::ByteSwapSerializedModel(&model_bytes, false);
#endif

::google::protobuf::Map<string, SignatureDef> signatures;
std::unique_ptr<TfLiteSession> session;
Expand Down Expand Up @@ -143,6 +146,9 @@ TEST(TfLiteSession, ResizeWithSameNumElementsTest) {
TF_ASSERT_OK(ReadFileToString(tensorflow::Env::Default(),
test_util::TestSrcDirPath(kTestModel),
&model_bytes));
#if FLATBUFFERS_LITTLEENDIAN == 0
tflite::FlatBufferModel::ByteSwapSerializedModel(&model_bytes, false);
#endif

::google::protobuf::Map<string, SignatureDef> signatures;
std::unique_ptr<TfLiteSession> session;
Expand Down Expand Up @@ -196,6 +202,9 @@ TEST(TfLiteSession, ModelFromLegacyConverterWithSigdef) {
TF_ASSERT_OK(ReadFileToString(tensorflow::Env::Default(),
test_util::TestSrcDirPath(kTestModelWithSigdef),
&model_bytes));
#if FLATBUFFERS_LITTLEENDIAN == 0
tflite::FlatBufferModel::ByteSwapSerializedModel(&model_bytes, false);
#endif

::google::protobuf::Map<string, SignatureDef> signatures;
std::unique_ptr<TfLiteSession> session;
Expand Down Expand Up @@ -644,6 +653,9 @@ Status BuildSessionInBatch(std::unique_ptr<TfLiteSession>* sess,
std::string model_bytes;
TF_RETURN_IF_ERROR(ReadFileToString(
Env::Default(), test_util::TestSrcDirPath(model_path), &model_bytes));
#if FLATBUFFERS_LITTLEENDIAN == 0
tflite::FlatBufferModel::ByteSwapSerializedModel(&model_bytes, false);
#endif
auto model = tflite::FlatBufferModel::BuildFromModel(
flatbuffers::GetRoot<tflite::Model>(model_bytes.data()));
const int model_batch_size = 5;
Expand Down Expand Up @@ -781,6 +793,9 @@ TEST(TfLiteSession, TestSetScheduler) {
TF_ASSERT_OK(ReadFileToString(Env::Default(),
test_util::TestSrcDirPath(kParseExampleModel),
&model_bytes));
#if FLATBUFFERS_LITTLEENDIAN == 0
tflite::FlatBufferModel::ByteSwapSerializedModel(&model_bytes, false);
#endif
auto model = tflite::FlatBufferModel::BuildFromModel(
flatbuffers::GetRoot<tflite::Model>(model_bytes.data()));
auto model_signature_def_map = GetTestSignatureDefMap();
Expand Down