def evaluate(hyper_params): if hyper_params["test_dataset_dirs"] is None: logging.fatal("Setting test_dataset_dirs in config file is mandatory for evaluation mode") return # Load the test set data data_processor = dataprocessor.DataProcessor(hyper_params["test_dataset_dirs"]) test_set = data_processor.get_dataset() logging.info("Using %d size of test set", len(test_set)) if len(test_set) == 0: logging.fatal("No files in test set during an evaluation mode") return with tf.Session() as sess: # create model model = AcousticModel(hyper_params["num_layers"], hyper_params["hidden_size"], hyper_params["batch_size"], hyper_params["max_input_seq_length"], hyper_params["max_target_seq_length"], hyper_params["input_dim"], hyper_params["batch_normalization"], hyper_params["char_map_length"]) model.create_forward_rnn() model.initialize(sess) model.restore(sess, hyper_params["checkpoint_dir"] + "/acoustic/") wer, cer = model.evaluate_full(sess, test_set, hyper_params["max_input_seq_length"], hyper_params["signal_processing"], hyper_params["char_map"]) print("Resulting WER : {0:.3g} %".format(wer)) print("Resulting CER : {0:.3g} %".format(cer)) return
def record_and_write(audio_processor, hyper_params): import pyaudio _CHUNK = hyper_params["max_input_seq_length"] _SR = 22050 p = pyaudio.PyAudio() with tf.Session() as sess: # create model model = AcousticModel(hyper_params["num_layers"], hyper_params["hidden_size"], 1, hyper_params["max_input_seq_length"], hyper_params["max_target_seq_length"], hyper_params["input_dim"], hyper_params["batch_normalization"], hyper_params["char_map_length"]) model.create_forward_rnn() model.initialize(sess) model.restore(sess, hyper_params["checkpoint_dir"] + "/acoustic/") # Create stream of listening stream = p.open(format=pyaudio.paInt16, channels=1, rate=_SR, input=True, frames_per_buffer=_CHUNK) print("NOW RECORDING...") while True: data = stream.read(_CHUNK) data = np.fromstring(data) feat_vec, original_feat_vec_length = audio_processor.process_signal(data, _SR) (a, b) = feat_vec.shape feat_vec = feat_vec.reshape((a, 1, b)) predictions = model.process_input(sess, feat_vec, [original_feat_vec_length]) result = [dataprocessor.DataProcessor.get_labels_str(hyper_params["char_map"], prediction) for prediction in predictions] print(result, end="")
def record_and_write(audio_processor, hyper_params): import pyaudio _CHUNK = hyper_params["max_input_seq_length"] _SR = 22050 p = pyaudio.PyAudio() with tf.Session() as sess: # create model model = AcousticModel(hyper_params["num_layers"], hyper_params["hidden_size"], 1, hyper_params["max_input_seq_length"], hyper_params["max_target_seq_length"], hyper_params["input_dim"], hyper_params["batch_normalization"], language=hyper_params["language"]) model.create_forward_rnn() model.initialize(sess) model.restore(sess, hyper_params["checkpoint_dir"]) # Create stream of listening stream = p.open(format=pyaudio.paInt16, channels=1, rate=_SR, input=True, frames_per_buffer=_CHUNK) print("NOW RECORDING...") while True: data = stream.read(_CHUNK) data = np.fromstring(data) feat_vec, original_feat_vec_length = audio_processor.process_signal(data, _SR) (a, b) = feat_vec.shape feat_vec = feat_vec.reshape((a, 1, b)) result = model.process_input(sess, feat_vec, [original_feat_vec_length]) print(result, end="")
def process_file(audio_processor, hyper_params, file): feat_vec, original_feat_vec_length = audio_processor.process_audio_file(file) if original_feat_vec_length > hyper_params["max_input_seq_length"]: logging.warning("File too long") return elif original_feat_vec_length < hyper_params["max_input_seq_length"]: # Pad the feat_vec with zeros pad_length = hyper_params["max_input_seq_length"] - original_feat_vec_length padding = np.zeros((pad_length, hyper_params["input_dim"]), dtype=np.float) feat_vec = np.concatenate((feat_vec, padding), 0) with tf.Session() as sess: # create model model = AcousticModel(hyper_params["num_layers"], hyper_params["hidden_size"], 1, hyper_params["max_input_seq_length"], hyper_params["max_target_seq_length"], hyper_params["input_dim"], hyper_params["batch_normalization"], hyper_params["char_map_length"]) model.create_forward_rnn() model.initialize(sess) model.restore(sess, hyper_params["checkpoint_dir"] + "/acoustic/") (a, b) = feat_vec.shape feat_vec = feat_vec.reshape((a, 1, b)) predictions = model.process_input(sess, feat_vec, [original_feat_vec_length]) transcribed_text = [dataprocessor.DataProcessor.get_labels_str(hyper_params["char_map"], prediction) for prediction in predictions] print(transcribed_text[0])
def evaluate(hyper_params): if hyper_params["test_dataset_dirs"] is None: logging.fatal("Setting test_dataset_dirs in config file is mandatory for evaluation mode") return # Load the test set data data_processor = dataprocessor.DataProcessor(hyper_params["test_dataset_dirs"]) test_set = data_processor.get_dataset() logging.info("Using %d size of test set", len(test_set)) if len(test_set) == 0: logging.fatal("No files in test set during an evaluation mode") return with tf.Session() as sess: # create model model = AcousticModel(hyper_params["num_layers"], hyper_params["hidden_size"], hyper_params["batch_size"], hyper_params["max_input_seq_length"], hyper_params["max_target_seq_length"], hyper_params["input_dim"], hyper_params["batch_normalization"], language=hyper_params["language"]) model.create_forward_rnn() model.initialize(sess) model.restore(sess, hyper_params["checkpoint_dir"]) wer, cer = model.evaluate_full(sess, test_set, hyper_params["max_input_seq_length"], hyper_params["signal_processing"]) print("Resulting WER : {0:.3g} %".format(wer)) print("Resulting CER : {0:.3g} %".format(cer)) return
def process_file(audio_processor, hyper_params, file): feat_vec, original_feat_vec_length = audio_processor.process_audio_file(file) if original_feat_vec_length > hyper_params["max_input_seq_length"]: logging.warning("File too long") return elif original_feat_vec_length < hyper_params["max_input_seq_length"]: # Pad the feat_vec with zeros pad_length = hyper_params["max_input_seq_length"] - original_feat_vec_length padding = np.zeros((pad_length, hyper_params["input_dim"]), dtype=np.float) feat_vec = np.concatenate((feat_vec, padding), 0) with tf.Session() as sess: # create model model = AcousticModel(hyper_params["num_layers"], hyper_params["hidden_size"], 1, hyper_params["max_input_seq_length"], hyper_params["max_target_seq_length"], hyper_params["input_dim"], hyper_params["batch_normalization"], hyper_params["char_map_length"]) model.create_forward_rnn() model.initialize(sess) model.restore(sess, hyper_params["checkpoint_dir"] + "/acoustic/") (a, b) = feat_vec.shape feat_vec = feat_vec.reshape((a, 1, b)) predictions = model.process_input(sess, feat_vec, [original_feat_vec_length]) transcribed_text = [dataprocessor.DataProcessor.get_labels_str(hyper_params["char_map"], prediction) for prediction in predictions] print(transcribed_text[0])
def test_create_forward_rnn(self): tf.reset_default_graph() with tf.Session(): model = AcousticModel(self.num_layers, self.hidden_size, self.batch_size, self.max_input_seq_length, self.max_target_seq_length, self.input_dim, self.normalization, self.num_labels) model.create_forward_rnn()
def process_file(audio_processor, hyper_params, file): feat_vec, original_feat_vec_length = audio_processor.process_audio_file(file) if original_feat_vec_length > hyper_params["max_input_seq_length"]: logging.warning("File too long") return with tf.Session() as sess: # create model model = AcousticModel(hyper_params["num_layers"], hyper_params["hidden_size"], 1, hyper_params["max_input_seq_length"], hyper_params["max_target_seq_length"], hyper_params["input_dim"], hyper_params["batch_normalization"], language=hyper_params["language"]) model.create_forward_rnn() model.initialize(sess) model.restore(sess, hyper_params["checkpoint_dir"]) (a, b) = feat_vec.shape feat_vec = feat_vec.reshape((a, 1, b)) transcribed_text = model.process_input(sess, feat_vec, [original_feat_vec_length]) print(transcribed_text[0])
def test_create_forward_rnn(self): tf.reset_default_graph() with tf.Session(): model = AcousticModel(self.num_layers, self.hidden_size, self.batch_size, self.max_input_seq_length, self.max_target_seq_length, self.input_dim, self.normalization, self.num_labels) model.create_forward_rnn()