def main( config: str = DEFAULT_YAML, saved: str = None, mxp: bool = False, bs: int = None, sentence_piece: bool = False, subwords: bool = False, device: int = 0, cpu: bool = False, output: str = "test.tsv", ): assert saved and output tf.random.set_seed(0) tf.keras.backend.clear_session() tf.config.optimizer.set_experimental_options({"auto_mixed_precision": mxp}) env_util.setup_devices([device], cpu=cpu) config = Config(config) speech_featurizer, text_featurizer = featurizer_helpers.prepare_featurizers( config=config, subwords=subwords, sentence_piece=sentence_piece, ) deepspeech2 = DeepSpeech2(**config.model_config, vocabulary_size=text_featurizer.num_classes) deepspeech2.make(speech_featurizer.shape) deepspeech2.load_weights(saved, by_name=True) deepspeech2.summary(line_length=100) deepspeech2.add_featurizers(speech_featurizer, text_featurizer) test_dataset = dataset_helpers.prepare_testing_datasets( config=config, speech_featurizer=speech_featurizer, text_featurizer=text_featurizer) batch_size = bs or config.learning_config.running_config.batch_size test_data_loader = test_dataset.create(batch_size) exec_helpers.run_testing(model=deepspeech2, test_dataset=test_dataset, test_data_loader=test_data_loader, output=output)
action="store_true", help="Whether to only use cpu") parser.add_argument("--output", type=str, default="test.tsv", help="Result filepath") args = parser.parse_args() assert args.saved tf.config.optimizer.set_experimental_options( {"auto_mixed_precision": args.mxp}) env_util.setup_devices([args.device], cpu=args.cpu) from tensorflow_asr.configs.config import Config from tensorflow_asr.datasets.asr_dataset import ASRTFRecordDataset, ASRSliceDataset from tensorflow_asr.featurizers.speech_featurizers import TFSpeechFeaturizer from tensorflow_asr.featurizers.text_featurizers import SubwordFeaturizer, SentencePieceFeaturizer, CharFeaturizer from tensorflow_asr.models.ctc.jasper import Jasper from tensorflow_asr.utils import app_util config = Config(args.config) speech_featurizer = TFSpeechFeaturizer(config.speech_config) if args.sentence_piece: print("Use SentencePiece ...") text_featurizer = SentencePieceFeaturizer(config.decoder_config) elif args.subwords: