前言
官方教程:Diffusers
本文主要内容:
本地使用Huggingface上的扩散模型说明:实验在Linux服务器上进行。
准备工作
安装库。
pip install --upgrade diffusers accelerate transformers
安装git lfs。
conda install git-lfs
修改环境变量
打开.bashrc文件。
vim ~/.bashrc
在最后一行添加镜像源。
export HF_ENDPOINT="https://hf-mirror/com"
使修改生效。
source ~/.bashrc
下载模型
执行download_model.py文件。
修改repo_id和cache_dir,分别为目标模型和保存路径。并设置token。
import os
from huggingface_hub import snapshot_download
while True:
try:
snapshot_download(repo_id="CompVis/stable-diffusion-v1-4", repo_type="model",
cache_dir="diff_models",
allow_patterns=["*"],
local_dir_use_symlinks=False, resume_download=True,
token='user_token')
break
except:
pass
使用模型
如图,点击“Use this model”可查看使用方式。