Stable Diffusion是一个开源的图像生成AI模型,可以部署在本地运行。部署步骤如下:
1. 准备环境:
- Python 3.6+
- CUDA 11.1+
- CuDNN 8.0+
- NVIDIA GPU (推荐RTX 2060或以上)
2. 安装依赖:
bash
pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
pip install omegaconf pytorch-lightning endothelin einops
3. 下载模型权重:
models.py已经内置了Carl Roux版的Stable Diffusion权重,你可以在 [这里](https://github.com/CompVis/stable-diffusion) 找到并下载其他权重。
4. 下载脚本代码:
bash
git clone https://github.com/CompVis/stable-diffusion.git
cd stable-diffusion
5. 生成图片:
bash
python scripts/generate.py --prompt "A scenic view of mountains near a lake"
generate.py脚本支持多种参数来生成不同风格的图片,具体可以参考仓库自带的文档。
6. 启动Web UI (可选):
如果想通过Web页面生成图片,可以启动stable-diffusion-webui:
bash
git clone https://github.com/yzubin/stable-diffusion-webui.git
cd stable-diffusion-webui
python app.py
然后在浏览器中访问 http://localhost:7860 即可使用Web UI生成图片。
以上步骤可以在本地成功部署并运行Stable Diffusion模型。如果在部署过程中遇到问题,可以参考仓库中的issues讨论,或在相关论坛搜索解决方案。
评论区