mirror of https://github.com/MycroftAI/mimic2.git
added export script
parent
0c0ad01cce
commit
925dbb613c
|
@ -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)
|
Loading…
Reference in New Issue