added export script

pull/15/head
Michael Nguyen 2018-07-11 16:13:00 -05:00
parent 0c0ad01cce
commit 925dbb613c
1 changed files with 52 additions and 0 deletions

52
export.py Normal file
View File

@ -0,0 +1,52 @@
import argparse
import tensorflow as tf
from synthesizer import Synthesizer
from models import create_model
from hparams import hparams, hparams_debug_string
from util import audio
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
'--checkpoint_path', required=True, help='path to model checkpoint'
)
parser.add_argument(
'--export_path', required=True, help='path to export model'
)
args = parser.parse_args()
builder = tf.saved_model.builder.SavedModelBuilder(args.export_path)
synth = Synthesizer()
synth.load(args.checkpoint_path)
inputs = tf.saved_model.utils.build_tensor_info(synth.model.inputs)
input_lengths = tf.saved_model.utils.build_tensor_info(
synth.model.input_lengths
)
wav_output = tf.saved_model.utils.build_tensor_info(synth.wav_output)
alignment = tf.saved_model.utils.build_tensor_info(synth.alignment)
prediction_signature = (
tf.saved_model.signature_def_utils.build_signature_def(
inputs={
'inputs': inputs,
"input_lengths": input_lengths
},
outputs={
'wav_output': wav_output,
'alignment': alignment
},
method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME)
)
with synth.session as sess:
builder.add_meta_graph_and_variables(
sess=sess,
tags=[tf.saved_model.tag_constants.SERVING],
signature_def_map={'predict': prediction_signature}
)
builder.save()
print("exported .pb to", args.export_path)