def test_evaluate(self): model_dir = os.path.abspath("tests/models/decode") gt_path = os.path.abspath("tests/data/toydict.test") params = Params(model_dir, gt_path) params.hparams = g2p_trainer_utils.load_params(model_dir) g2p_model = G2PModel(params, test_path=gt_path) g2p_model.evaluate() correct, errors = g2p_model.calc_errors(gt_path) self.assertAlmostEqual(float(errors)/(correct+errors), 1.000, places=3)
def test_decode(self): model_dir = os.path.abspath("tests/models/decode") decode_file_path = os.path.abspath("tests/data/toydict.graphemes") output_file_path = os.path.abspath("tests/models/decode/decode_output.txt") params = Params(model_dir, decode_file_path) params.hparams = g2p_trainer_utils.load_params(model_dir) g2p_model = G2PModel(params, test_path=decode_file_path) g2p_model.decode(output_file_path=output_file_path) out_lines = open(output_file_path).readlines() self.assertEqual(out_lines[0].strip(), u"") self.assertEqual(out_lines[1].strip(), u"") self.assertEqual(out_lines[2].strip(), u"") os.remove(output_file_path)
def test_decode(self): model_dir = os.path.abspath("tests/models/decode") decode_file_path = os.path.abspath("tests/data/toydict.graphemes") output_file_path = os.path.abspath("tests/models/decode/decode_output.txt") params = Params(model_dir, decode_file_path) params.hparams = g2p_trainer_utils.load_params(model_dir) g2p_model = G2PModel(params, test_path=decode_file_path) g2p_model.decode(output_file_path=output_file_path) out_lines = open(output_file_path).readlines() self.assertEqual(out_lines[0].strip(), "cb") self.assertEqual(out_lines[1].strip(), "abcabac") self.assertEqual(out_lines[2].strip(), "a") os.remove(output_file_path)
def main(_=[]): """Main function. """ tf.logging.set_verbosity(tf.logging.INFO) file_path = FLAGS.train or FLAGS.decode or FLAGS.evaluate test_path = FLAGS.decode or FLAGS.evaluate or FLAGS.test if not FLAGS.model_dir: raise RuntimeError("Model directory not specified.") if FLAGS.reinit and os.path.exists(FLAGS.model_dir): shutil.rmtree(FLAGS.model_dir) if not os.path.exists(FLAGS.model_dir): os.makedirs(FLAGS.model_dir) params = Params(FLAGS.model_dir, file_path, flags=FLAGS) if FLAGS.train: g2p_trainer_utils.save_params(FLAGS.model_dir, params.hparams) g2p_model = G2PModel(params, train_path=FLAGS.train, dev_path=FLAGS.valid, test_path=test_path, cleanup=FLAGS.cleanup, p2g_mode=FLAGS.p2g) g2p_model.train() else: params.hparams = g2p_trainer_utils.load_params(FLAGS.model_dir) g2p_model = G2PModel(params, test_path=test_path, p2g_mode=FLAGS.p2g) if FLAGS.freeze: g2p_model.freeze() elif FLAGS.interactive: g2p_model.interactive() elif FLAGS.decode: g2p_model.decode(output_file_path=FLAGS.output) elif FLAGS.evaluate: g2p_model.evaluate()
import sys import os from g2p_seq2seq import g2p import g2p_seq2seq.g2p_trainer_utils as g2p_trainer_utils from g2p_seq2seq.g2p import G2PModel from g2p_seq2seq.params import Params from flask import Flask, jsonify from flask import request, url_for from flask_api import FlaskAPI, status, exceptions app = FlaskAPI(__name__) params = Params("g2p-seq2seq", '') params.hparams = g2p_trainer_utils.load_params("g2p-seq2seq") model = G2PModel(params) model.inputs = [] # initialization model._G2PModel__prepare_interactive_model() @app.route("/", methods=['POST']) def notes_list(): wordObtained = str(request.data.get('text', '')) output = model.decode_word(wordObtained) if (not output): return "" else: return output[0] @app.route("/", methods=["GET"])
def path_leaf(path): head, tail = ntpath.split(path) return tail or ntpath.basename(head) MODELDIR = "g2p-seq2seq-model" DATADIR = g.DICTDIRTXT #decode_file_path = os.path.abspath("/home/mike/SR_Py/helperScripts/Dictionary(Auto)/Thing.txt") output_file_path = g.DICTDIR # print(model_dir) # params = Params(model_dir, decode_file_path) # params.hparams = g2p_trainer_utils.load_params(model_dir) # g2p_model = G2PModel(params, test_path=decode_file_path) # g2p_model.decode(output_file_path=output_file_path) clear_dir(output_file_path) filesIn = glob.glob(DATADIR + "/*") for filenameIn in filesIn: filesOut = filenameIn.split('.')[0] fileOut = path_leaf(filesOut) input = filenameIn output = os.path.join(output_file_path, fileOut + ".dic") params = Params(MODELDIR, input) params.hparams = g2p_trainer_utils.load_params(MODELDIR) g2p_model = G2PModel(params, test_path=input) g2p_model.decode(output_file_path=output)
import sys import os from g2p_seq2seq import g2p import g2p_seq2seq.g2p_trainer_utils as g2p_trainer_utils from g2p_seq2seq.g2p import G2PModel from g2p_seq2seq.params import Params print("hello") model_dir = os.path.abspath("models/g2p-seq2seq") gt_path = os.path.abspath("data/toydict.test") params = Params(model_dir, gt_path) params.hparams = g2p_trainer_utils.load_params(model_dir) g2p_model = G2PModel(params, test_path=gt_path) g2p_model.decode_word("hello")