Stable Diffusion 跑通总结

打印 上一主题 下一主题

主题 1906|帖子 1906|积分 5718

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
记录了自己跑通Stable Diffusion的过程和踩过的坑,目前只是初步跑了一下,没有很深入的使用代码,希望能有一些参考代价。
 在Windows体系运行,必要提前装好Conda
一、下载代码和模型

1、下载代码:

代码下载:代码地址
大概
  1. git clone https://github.com/CompVis/stable-diffusion.git
复制代码
2、下载预训练模型:

a.下载sd-v1-4.ckpt模型

地址:模型地址
按照下列顺序点击下载模型


红圈模型有4G,下面的模型有7G,自行选择下载


  • 在stable-diffusion-main\models\ldm路径下创建文件夹stable-diffusion-v1,将模型放在里面
  • 将模型名称改为model.ckpt



b.下载clip-vit-large-patch14模型

模型地址

下载红框内文件。


  • 放置在路径stable-diffusion-main\openai\clip-vit-large-patch14下,自己创建路径。


c.下载safety_checker模型

模型地址

依旧下载红框内文件


  • 文件存放在stable-diffusion-main\CompVis\stable-diffusion-safety-checker下,自行创建路径。
  • 将这次下载的safety_checker_config文件命名为config.json
  • 将上一块中下载的preprocessor_config.json文件粘贴过来

二、配置环境

使用conda配置环境,在Anaconda Prompt下指向stable-diffusion-main文件夹,运行:
  1. conda env create -f environment.yaml
复制代码
报错:
  1. Installing pip dependencies: - Ran pip subprocess with arguments:
  2. ['C:\Users\neals\.conda\envs\ldm\python.exe', '-m', 'pip', 'install', '-U', '-r', 'I:\tmp\sd\stable-diffusion-main\condaenv.wws0680u.requirements.txt', '--exists-action=b']
  3. Pip subprocess output:
  4. Obtaining taming-transformers from git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers (from -r I:\tmp\sd\stable-diffusion-main\condaenv.wws0680u.requirements.txt (line 17))
  5. Cloning https://github.com/CompVis/taming-transformers.git (to revision master) to i:\tmp\sd\stable-diffusion-main\src\taming-transformers
  6. Pip subprocess error:
  7. ERROR: Command errored out with exit status 128: git clone -q https://github.com/CompVis/taming-transformers.git 'I:\tmp\sd\stable-diffusion-main\src\taming-transformers' Check the logs for full command output.
  8. failed
  9. CondaEnvException: Pip failed
复制代码
将environment.yaml中的这两行删掉:
  1. - -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
  2. - -e git+https://github.com/openai/CLIP.git@main#egg=clip
复制代码
改用pip下令自己手动配置这两个包:
  1. pip install taming-transformers
  2. pip install clip
复制代码
但是environment.yaml总是报错大概conda总是卡住,把文件里pip后的部分用一个requirements.txt存储,使用pip安装:(假如pytorch这些没装上就手动安装一下)
  1. pip install -r requirements.txt
复制代码
下载太慢就给pip配上清华源,教程
三、运行代码

我运行的是文本生成图像任务,在终端中输入指令:
  1. python scripts/txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms
复制代码
运气好的话直接就能生成图像,生成的图像存储在outputs\txt2img-samples\samples下。

报错 ModuleNotFoundError: No module named ‘ldm’:

这里报错的ldm是指stable-diffusion-main文件夹下的ldm文件夹。
解决方法:
将scripts文件夹下的全部内容复制到stable-diffusion-main文件夹下,指令改为:
  1. python txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms
复制代码

报错 ImportError: cannot import name 'VectorQuantizer2' from 'taming.modules.vqvae.quantize'

原因:taming库的版本题目
解决方法:
将stable-diffusion-main\ldm\models下的autoencoder.py中的:
  1. from taming.modules.vqvae.quantize import VectorQuantizer2 as VectorQuantizer
复制代码
改为:
  1. from taming.modules.vqvae.quantize import VectorQuantizer
复制代码

报错:RuntimeError: CUDA out of memory.

原因:显卡的内存不敷
可能的解决方法:
在终端里使用指令:
  1. python txt2img.py --prompt "a photograph of an astronaut riding a horse" --plms --n_samples 1
复制代码
设置n_samples=1运行,大概在txt2img.py文件中修改这个参数为1。
n_samples的注释是:how many samples to produce for each given prompt. A.k.a. batch size
假如更改后还是内存不敷,可以去看看有没有什么其他的参数可以修改,试试能不能减少显卡用量。

报错couldn't connect to 'https://huggingface.co'

原因:没有搜索到本地下载好的模型,试图毗连https://huggingface.co失败
查抄模型是否下好了,位置和命名是否正确。



跑通后的生成的一些图像:



参考链接,感谢大佬们的辅导:
AIGC:文生图模型Stable Diffusion-CSDN博客
latent diffusion model 复现题目记录-CSDN博客
Diffusion程序调试相干题目汇总-CSDN博客

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

南飓风

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表