update inference script
Browse filesFiles changed (3)
32 unmodified lines333435363738170 unmodified lines20921021121221321421532 unmodified lines2482492502512522532543 unmodified lines25825926026126226326426526626726819 unmodified lines28828929029129229329429529629729829930030130230330432 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"LANG_ID_MAPPING = {"hi": 0,170 unmodified linesreturn audio_padded, cers, lengths, langs, filenamesclass PreProcessBatch(torch.utils.data.Dataset):def __init__(self, manifest_path, cer, langid):with open(manifest_path, "r") as f:data = f.read().split("\n")delim = "\t"32 unmodified linesaudio, sr = torchaudio.load(audio_path)return audio.squeeze(), cer, langid, keydef score(audio_path, cer=None, langid=None, use_cer=False, use_langid=False, download_path="hf_inference_models", device="cpu"):"""Single audio mos prediction"""3 unmodified linesscore = mos_model(audio, cer_data=cer, lang_data=langid).squeeze().cpu().item()return scoredef 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"):"""batch audio mos prediction"""dataset = PreProcessBatch(manifest_path, cer, 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 linesraise ValueError("Please provide manifest_path for batch inference")cer = Noneif 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:###FIX THISscore = 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)32 unmodified lines33343536373839170 unmodified lines21021121221321421521632 unmodified lines2492502512522532542553 unmodified lines25926026126226326426526626726826919 unmodified lines28929029129229329429529629729829930030130230330430532 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 linesreturn audio_padded, cers, lengths, langs, filenamesclass PreProcessBatch(torch.utils.data.Dataset):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 linesaudio, sr = torchaudio.load(audio_path)return audio.squeeze(), cer, langid, keydef 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 linesscore = mos_model(audio, cer_data=cer, lang_data=langid).squeeze().cpu().item()return scoredef 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, 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 linesraise 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")langid = None# langid = "kn"# 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, use_cer=args.use_cer, use_langid=args.use_langid, device=args.device)
1234id audio_path langid1 ../sample_audio/kn_audio1.wav2 ../sample_audio/hi_audio2.wav4 ../sample_audio/mr_audio3.wav1234id audio_path1 ../sample_audio/kn_audio1.wav2 ../sample_audio/hi_audio2.wav3 ../sample_audio/mr_audio3.wav
1234id audio_path langid1 ../sample_audio/kn_audio1.wav kn2 ../sample_audio/hi_audio2.wav hi4 ../sample_audio/mr_audio3.wav mr1234id audio_path langid1 ../sample_audio/kn_audio1.wav kn2 ../sample_audio/hi_audio2.wav hi3 ../sample_audio/mr_audio3.wav mr
infer_indicmos.py+14-13
sample_manifest/manifest.txt+2-2
sample_manifest/manifest_lang.txt+1-1