def run_testing( model: BaseModel, test_dataset: ASRSliceDataset, test_data_loader: tf.data.Dataset, output: str, ): with file_util.save_file(file_util.preprocess_paths(output)) as filepath: overwrite = True if tf.io.gfile.exists(filepath): overwrite = input(f"Overwrite existing result file {filepath} ? (y/n): ").lower() == "y" if overwrite: results = model.predict(test_data_loader, verbose=1) logger.info(f"Saving result to {output} ...") with open(filepath, "w") as openfile: openfile.write("PATH\tDURATION\tGROUNDTRUTH\tGREEDY\tBEAMSEARCH\n") progbar = tqdm(total=test_dataset.total_steps, unit="batch") for i, pred in enumerate(results): groundtruth, greedy, beamsearch = [x.decode("utf-8") for x in pred] path, duration, _ = test_dataset.entries[i] openfile.write(f"{path}\t{duration}\t{groundtruth}\t{greedy}\t{beamsearch}\n") progbar.update(1) progbar.close() app_util.evaluate_results(filepath)
jasper.load_weights(args.saved) jasper.summary(line_length=100) jasper.add_featurizers(speech_featurizer, text_featurizer) batch_size = args.bs or config.learning_config.running_config.batch_size test_data_loader = test_dataset.create(batch_size) with file_util.save_file(file_util.preprocess_paths(args.output)) as filepath: overwrite = True if tf.io.gfile.exists(filepath): overwrite = input( f"Overwrite existing result file {filepath} ? (y/n): ").lower( ) == "y" if overwrite: results = jasper.predict(test_data_loader, verbose=1) print(f"Saving result to {args.output} ...") with open(filepath, "w") as openfile: openfile.write("PATH\tDURATION\tGROUNDTRUTH\tGREEDY\tBEAMSEARCH\n") progbar = tqdm(total=test_dataset.total_steps, unit="batch") for i, pred in enumerate(results): groundtruth, greedy, beamsearch = [ x.decode('utf-8') for x in pred ] path, duration, _ = test_dataset.entries[i] openfile.write( f"{path}\t{duration}\t{groundtruth}\t{greedy}\t{beamsearch}\n" ) progbar.update(1) progbar.close() app_util.evaluate_results(filepath)