U 6¨!d’ã@s–ddlZddlmZmZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZddlmZddlmZdd lmZGd d „d ƒZdS) éN)ÚgmtimeÚstrftime)ÚArgumentParser)ÚCropAndExtract)Ú Audio2Coeff)ÚAnimateFromCoeff)Úget_data)Úget_facerender_data)Ú text2speechc@seZdZddd„Zdd„ZdS)Ú SadTalkerÚ checkpointscCsLtj ¡rd}nd}tjd}tj |¡d}d}tj |d¡tj d<tj |dd¡}tj |dd¡}tj |dd ¡}tj |dd ¡} tj |dd ¡} tj |d d ¡} tj |dd¡} tj |d d¡} tj |dd¡}tj |dd¡}tj |d d¡}t |ƒt ||||ƒ|_ t | ƒt | | | | | |ƒ|_t |ƒt||||ƒ|_||_dS)NÚcudaZcpurz./r Z TORCH_HOMEz%shape_predictor_68_face_landmarks.datz epoch_20.pthZ BFM_Fittingz wav2lip.pthzauido2pose_00140-model.pthÚconfigzauido2pose.yamlzauido2exp_00300-model.pthzauido2exp.yamlzfacevid2vid_00189-model.pth.tarzmapping_00229-model.pth.tarzfacerender.yaml)Útorchr Ú is_availableÚsysÚargvÚosÚpathÚsplitÚjoinÚenvironÚprintrÚpreprocess_modelrÚaudio_to_coeffrÚanimate_from_coeffÚdevice)ÚselfZcheckpoint_pathrÚcurrent_code_pathZ modules_pathÚcurrent_root_pathZpath_of_lm_croperZpath_of_net_recon_modelZdir_of_BFM_fittingZwav2lip_checkpointZaudio2pose_checkpointZaudio2pose_yaml_pathZaudio2exp_checkpointZaudio2exp_yaml_pathZfree_view_checkpointZmapping_checkpointZfacerender_yaml_path©r úL/apdcephfs/private_shadowcun/sadtalker-huggingface/modules/sadtalker_test.pyÚ__init__sB  ÿÿzSadTalker.__init__cCsntdƒ}tj ||¡}tj|ddtj |d¡}tj|ddt|ƒtj |tj |¡¡}t ||¡tj  |¡rštj |tj |¡¡}t ||¡nt tj|ddd} tj |d¡} tj| dd|j   || ¡\} } | dkrît dƒ‚t| ||jƒ} |j  | || ¡}d}t|| | ||ƒ}|j  ||¡|d }td |›d |›ƒtj ||d ¡tj ||d ¡fS) Nz%Y_%m_%d_%H.%M.%ST)Úexist_okÚinputrÚfirst_frame_dirzNo face is detectedéÚ video_namezThe generated video is named z in z.mp4)rrrrÚmakedirsrÚbasenameÚshutilÚmoveÚisfiler rÚgenerateÚAttributeErrorrrrr r)rÚ source_imageÚ driven_audioÚ result_dirZtime_tagÚsave_dirZ input_dirZpic_pathÚ audio_pathZ pose_styler%Zfirst_coeff_pathZ crop_pic_pathÚbatchZ coeff_pathÚ batch_sizeÚdatar'r r r!Útest8s6  zSadTalker.testN)r )Ú__name__Ú __module__Ú __qualname__r"r7r r r r!r s )r )rÚtimerrrrr*ÚargparserZsrc.utils.preprocessrZsrc.test_audio2coeffrZsrc.facerender.animaterZsrc.generate_batchrZsrc.generate_facerender_batchr Úmodules.text2speechr r r r r r!Ús