发布日期:2026-08-13 | 分类:AI工具教程
FaceChain FACT是阿里巴巴开源的AI人像写真生成项目全新版本,摒弃传统训练过程,单图zero-shot直接生成目标人像。支持丰富风格模板,已在商业应用中广泛使用。GitHub仓库:modelscope/FaceChain。
git clone https://github.com/modelscope/FaceChain.git
cd FaceChain
git checkout fact # 切换到FACT分支
# 方式1:pip安装
pip install -r requirements.txt
pip install -r requirements_fact.txt
# 方式2:Docker一键部署(推荐)
docker pull registry.cn-hangzhou.aliyuncs.com/modelscope/facechain-fact:latest
docker run -d --gpus all -p 7860:7860 \
-v $(pwd)/outputs:/app/outputs \
registry.cn-hangzhou.aliyuncs.com/modelscope/facechain-fact:latest
# 模型自动从ModelScope下载,无需手动操作
# 如需手动下载:
pip install modelscope
python -c "from modelscope import snapshot_download; snapshot_download('modelscope/FaceChain-FACT')"
# 启动Gradio Web UI
python app_fact.py
# 浏览器访问 http://localhost:7860
from facechain.fact import FaceChainFACT
# 初始化
generator = FaceChainFACT(device="cuda")
# 单图生成写真
result = generator.generate(
source_image="photo.jpg", # 输入人脸照片
style="business", # 风格:business/casual/art/ancient
num_outputs=4, # 生成数量
guidance_scale=7.5, # 引导强度
seed=42 # 随机种子
)
# 保存结果
for i, img in enumerate(result.images):
img.save(f"portrait_{i}.png")
styles = ["business", "casual", "graduation", "ancient", "art"]
for style in styles:
result = generator.generate(
source_image="photo.jpg",
style=style,
num_outputs=2
)
for i, img in enumerate(result.images):
img.save(f"portrait_{style}_{i}.png")
Q: 显存不够怎么办?
A: 设置--lowvram参数,或使用CPU模式(速度慢10倍)。
Q: 生成效果不好?
A: 确保输入照片正脸清晰、光线充足、分辨率≥512x512。
FaceChain FACT是阿里巴巴开源的AI人像写真生成项目全新版本,摒弃传统训练过程,单图zero-shot直接生成目标人像。支持丰富风格模板,已在商业应用中广泛使用。GitHub仓库:modelscope/FaceChain。
IOPaint AI图像处理教程