开源换脸软件FaceFusion安装教程
Windows 环境安装
winget install -e --id Git.Git winget install -e --id Anaconda.Miniconda3 --version py312_25.1.1-2 --override "/AddToPath=1" winget install -e --id Gyan.FFmpeg --version 7.0.2准备环境
conda init --all conda create --name facefusion python=3.12 pip=25.0 conda activate facefusion安装加速器
conda install nvidia/label/cuda-12.9.1::cuda-runtime nvidia/label/cudnn-9.10.0::cudnn
pip install tensorrt==10.12.0.36 --extra-index-url https://pypi.nvidia.com
下载FaceFusion
gitclone https://github.com/facefusion/facefusioncdfacefusion安装应用
# CPUpython install.py--onnxruntimedefault#CUDApython install.py--onnxruntimecuda#DirectMLpython install.py--onnxruntimedirectml可能出现的错误
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is thesourceof the following dependency conflicts. opencv-python4.12.0.88 requires numpy<2.3.0,>=2;python_version>="3.9", but you have numpy2.4.6whichis incompatible.解决办法
pipinstall"numpy<2.3.0,>=1.21"--force-reinstall重启环境
conda deactivate conda activate facefusion默认运行命令
python facefusion.py run --open-browser第一次 运行 (下载模型)
python facefusion.py run --download-provider huggingface --open-browser删掉 “C:\Users\Qingdaer\facefusion\facefusion\choices.py” 中的
'https://huggingface.co',修改临时文件夹到D盘来防止C盘爆满导致任务失败
python facefusion.py run --open-browser --temp-path D:\facefusion_tempfacefusion新版解除nsfw方法
修改"C:\Users\Qingdaer\facefusion\facefusion\content_analyser.py"文件
defpre_check()->bool:model_hash_set,model_source_set=collect_model_downloads()# return conditional_download_hashes(model_hash_set) and conditional_download_sources(model_source_set)returnFalsedefanalyse_frame(vision_frame:VisionFrame)->bool:# return detect_nsfw(vision_frame)returnFalse修改"C:\Users\Qingdaer\facefusion\facefusion\core.py"文件
defcommon_pre_check()->bool:common_modules=\[content_analyser,face_classifier,face_detector,face_landmarker,face_masker,face_recognizer,voice_extractor]content_analyser_content=inspect.getsource(content_analyser).encode()content_analyser_hash=hash_helper.create_hash(content_analyser_content)# return all(module.pre_check() for module in common_modules) and content_analyser_hash == 'b14e7b92'returnTrue网页中下载模型加速
在 “C:\Users\Qingdaer\facefusion\facefusion.py” 文件中添加
importos os.environ["HF_ENDPOINT"]="https://hf-mirror.com"成功运行终端示例
C:\Users\Qingdaer\facefusion>conda activate facefusion&&python facefusion.py run --open-browser --temp-path D:\facefusion_temp * Running onlocalURL: http://127.0.0.1:7860 * To create a public link,set`share=True`in`launch()`.[FACEFUSION.CORE]processing step1of1analysing:100%|=====================================================|56276/56276[02:03<00:00,454.08frame/s,rate=0][FACEFUSION.IMAGE_TO_VIDEO]extracting frames with a resolution of 1280x720 and23.97602420302018frames per second extracting:100%|============================================================|56276/56276[09:08<00:00,102.67frame/s]processing:100%|===========================|56276/56276[48:53<00:00,19.19frame/s,execution_providers=['directml']][FACEFUSION.IMAGE_TO_VIDEO]merging video with a resolution of 1280x720 and23.97602420302018frames per second merging:100%|================================================================|56276/56276[15:28<00:00,60.63frame/s][FACEFUSION.IMAGE_TO_VIDEO]processing to video succeededin4561.66seconds