update inference script
Browse filesFiles changed (3)
32 unmodified lines33343536373839170 unmodified lines21021121221221321421521632 unmodified lines2492502512512522532542553 unmodified lines25926026126126226326426526526626726826919 unmodified lines28929029129129229329229329429529629629729829829930030130229930030130230330430532 unmodified linesCER_PREDICTOR = "joint_indicw2v_base_cer.pt"LANG_ID_PREDICTOR = "joint_indicw2v_base_lang.pt"CER_LANG_ID_PREDICTOR = "joint_indicw2v_base_cer_lang.pt"HF_PATH = "hf_inference_models"
LANG_ID_MAPPING = { "hi": 0,170 unmodified lines return audio_padded, cers, lengths, langs, filenames class PreProcessBatch(torch.utils.data.Dataset): def __init__(self, manifest_path, cer, langid): def __init__(self, manifest_path, use_cer, use_langid): with open(manifest_path, "r") as f: data = f.read().split("\n") delim = "\t"32 unmodified lines audio, sr = torchaudio.load(audio_path) return audio.squeeze(), cer, langid, key
def score(audio_path, cer=None, langid=None, use_cer=False, use_langid=False, download_path="hf_inference_models", device="cpu"):def score(audio_path, cer=None, langid=None, use_cer=False, use_langid=False, download_path=HF_PATH, device="cpu"): """ Single audio mos prediction """3 unmodified lines score = mos_model(audio, cer_data=cer, lang_data=langid).squeeze().cpu().item() return score
def batch_score(manifest_path, save_path, batch_size=32, cer=None, langid=None, use_cer=False, use_langid=False, download_path="hf_inference_models", device="cpu"):def batch_score(manifest_path, save_path, batch_size=32, use_cer=False, use_langid=False, download_path="hf_inference_models", device="cpu"): """ batch audio mos prediction """ dataset = PreProcessBatch(manifest_path, cer, langid) dataset = PreProcessBatch(manifest_path, use_cer, use_langid) loader = torch.utils.data.DataLoader(dataset, batch_size=args.batch_size, shuffle=False, collate_fn=Collate()) mos_model = load_model(use_cer, use_langid, download_path, device) results = {}19 unmodified lines raise ValueError("Please provide manifest_path for batch inference") cer = None if cer is not None: if cer > 1: print("WARNING: Use raw CER value, not percentage") # if cer is not None: # if cer > 1: # print("WARNING: Use raw CER value, not percentage") langid = None # langid = "kn" if args.audio_path is not None: # if args.audio_path is not None: ###FIX THIS score = score(audio_path=args.audio_path, cer=cer, langid=langid, use_cer=args.use_cer, use_langid=args.use_langid) print("predicted MOS", score) else: assert args.save_path is not None, "Please provide a file path for the batch scores to be saved - save_path" batch_score(manifest_path=args.manifest_path, save_path=args.save_path, batch_size=args.batch_size, cer=cer, langid=langid, use_cer=args.use_cer, use_langid=args.use_langid, device=args.device) # score = score(audio_path=args.audio_path, cer=cer, langid=langid, use_cer=args.use_cer, use_langid=args.use_langid) # print("predicted MOS", score) # else: assert args.save_path is not None, "Please provide a file path for the batch scores to be saved - save_path" batch_score(manifest_path=args.manifest_path, save_path=args.save_path, batch_size=args.batch_size, use_cer=args.use_cer, use_langid=args.use_langid, device=args.device)
112344id audio_path langidid audio_path1 ../sample_audio/kn_audio1.wav2 ../sample_audio/hi_audio2.wav4 ../sample_audio/mr_audio3.wav3 ../sample_audio/mr_audio3.wav12344id audio_path langid1 ../sample_audio/kn_audio1.wav kn2 ../sample_audio/hi_audio2.wav hi4 ../sample_audio/mr_audio3.wav mr3 ../sample_audio/mr_audio3.wav mrinfer_indicmos.py+14-13
sample_manifest/manifest.txt+2-2
sample_manifest/manifest_lang.txt+1-1