Skip to content

Instantly share code, notes, and snippets.

@MartinNowak
Created November 28, 2019 16:17
Show Gist options
  • Save MartinNowak/9a2e467d740c43fe7e6fef6c09502449 to your computer and use it in GitHub Desktop.
Save MartinNowak/9a2e467d740c43fe7e6fef6c09502449 to your computer and use it in GitHub Desktop.
Convert TF saved model from protobuf binary to text format
import os, sys
import google.protobuf
from tensorflow.core.protobuf import saved_model_pb2
import tensorflow as tf
def convert_saved_model_to_pbtxt(path):
saved_model = saved_model_pb2.SavedModel()
with open(os.path.join(path, 'saved_model.pb'), 'rb') as f:
saved_model.ParseFromString(f.read())
with open(os.path.join(path, 'saved_model.pbtxt'), 'w') as f:
f.write(google.protobuf.text_format.MessageToString(saved_model))
for path in sys.argv[1:]:
convert_saved_model_to_pbtxt(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment