复现问题记录 | Stable Diffusion(LDM) (in python3)(一)

这篇具有很好参考价值的文章主要介绍了复现问题记录 | Stable Diffusion(LDM) (in python3)(一)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


记录复现LDM遇到的问题

环境


conda env create -f environment.yaml
根据environment.yaml创建一个叫ldm的新环境
其中报错是需要github下载的两个模型无法获取,通过VPN单独下载

  • 根据报错信息显示代码放在./src文件夹下
Installing pip dependencies: \ Ran pip subprocess with arguments:
['/home/****/.conda/envs/ldm/bin/python', '-m', 'pip', 'install', '-U', '-r', '/mnt/****/****/latent-diffusion-main/condaenv.ie4dsr_m.requirements.txt']
Pip subprocess output:
Obtaining taming-transformers from git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers (from -r /mnt/****/****/latent-diffusion-main/condaenv.ie4dsr_m.requirements.txt (line 13))
  Cloning https://github.com/CompVis/taming-transformers.git (to revision master) to ./src/taming-transformers

Pip subprocess error:
ERROR: Command errored out with exit status 128: git clone -q https://github.com/CompVis/taming-transformers.git /mnt/****/****/latent-diffusion-main/src/taming-transformers Check the logs for full command output.
                                                                                                                                                       failed

CondaEnvException: Pip failed
  • 注意一下模型的文件名,根据报错和yaml分析,这里应该是用的environment.yaml里#egg后面的名字
#environment.yaml
...
  	- -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
    - -e git+https://github.com/openai/CLIP.git@main#egg=clip
    - -e .

放到对应位置后还是不能用,再
pip install taming-transformers
以及
pip install clip
安装很流畅,现在可以正常运行了
可以看到,两个从github手动安装的模型放在这个路径
/home/user/.conda/envs/ldm/lib/python3.8/site-packages/xxx(taming, clip)/

比较疑惑的是如果第一次安装出了问题,想要重新装environment.yaml时,不知道如何利用environment更新已有环境。直接用上面的口令会报下面的错,搜索了很久没有找到解决方案。

CondaValueError: prefix already exists: /home/fangfei/.conda/envs/ldm

更新 解决方案
conda env update -n environment_name -f environment.yaml 即可依据environment.yaml更新环境
如果不指定-n则更新到environment.yaml中命名的环境中
参考链接

代码


util.py

def instantiate_from_config(config):
	...
	# 根据target位置,返回一个函数,对函数输入params中参数
	return get_obj_from_str(config["target"])(**config.get("params", dict()))
	
def get_obj_from_str(string, reload=False):
	module, cls = string.rsplit(".", 1)
	...
	return getattr(importlib.import_module(module, package=None), cls)
  1. getattr(object, name[, default]) 用于返回一个对象属性值。
    例子:
>>>class A(object):
...     bar = 1
... 
>>> a = A()
>>> getattr(a, 'bar')        # 获取属性 bar 值
1
>>> getattr(a, 'bar2')       # 属性 bar2 不存在,触发异常
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute 'bar2'
>>> getattr(a, 'bar2', 3)    # 属性 bar2 不存在,但设置了默认值
3
>>>
  1. import动态导入模块

测试

测试的代码在./script/下

Text-to-Image

首先测试T2I功能,根据README.md
下载pre-trained weights (5.7GB)

mkdir -p models/ldm/text2img-large/
wget -O models/ldm/text2img-large/model.ckpt https://ommer-lab.com/files/latent-diffusion/nitro/txt2img-f8-large/model.ckpt

采样#1

# 官方采样指令
python scripts/txt2img.py 
		--prompt "a virus monster is playing guitar, oil on canvas" 
		--ddim_eta 0.0 
		--n_samples 4 
		--n_iter 4 
		--scale 5.0  
		--ddim_steps 50

This will save each sample individually as well as a grid of size n_iter x n_samples at the specified output location (default: outputs/txt2img-samples).

采样#2

python scripts/txt2img.py 
		--prompt "a painting of a virus monster playing guitar" 
       	--outdir ./outputs/txt2img-samples
        --plms
        --ckpt ./models/ldm/sd-v1-4.ckpt 
       	--ddim_steps 100 
        --H 512 
        --W 512 
        --seed 8

其中sd-v1-4.ckpt 在ComVis下载。按网页指引申请权限就可以获得了,很友好。

直接使用网页生成

stable diffusion文章来源地址https://www.toymoban.com/news/detail-416900.html

到了这里,关于复现问题记录 | Stable Diffusion(LDM) (in python3)(一)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • stable-diffusion基础问题记录

    1、启动 如果自己是anaconda,python版本不是3.10.6 conda create -n python_3_10_6 python=3.10.6,创建一个这样的环境 修改webui-user.bat set PYTHON=D:/software/Anaconda3/envs/python_3_10_6/python,把python换成这个版本 然后再启动bat 2、下载gfpgan的时候,如果遇到这种情况:使用国内的网会卡住,使用国外

    2024年02月09日
    浏览(27)
  • Stable Diffusion ubuntu 部署,问题记录

    在使用图生图时,报错 NansException: A tensor with all NaNs was produced in Unet. This could be either because there\\\'s not enough precision to represent the picture, or because your video card does not support half type. Try setting the \\\"Upcast cross attention layer to float32\\\" option in Settings Stable Diffusion or using the --no-half commandline a

    2024年02月06日
    浏览(35)
  • stable-diffusion-webui一些问题记录

    1、中间有一个巨慢的clone操作,实际上自己能手动clone git clone https://github.com/Stability-AI/stablediffusion.git git clone https://github.com/CompVis/taming-transformers.git git clone https://github.com/crowsonkb/k-diffusion.git git clone https://github.com/sczhou/CodeFormer.git git clone https://github.com/salesforce/BLIP.git

    2024年02月12日
    浏览(34)
  • stable-diffusion-webui 安装问题记录

    安装完成后,浏览器打开:http://127.0.0.1:7860/,无论点哪里,只要触发交互,都提示: 解决办法: 1、关闭(墙外魔法工具)软件(不一定有效) 2、需要不关魔法工具的环境下的话,可以修改webui-user.bat文件(Linux系统对应webui-user.sh),增加参数:–no-gradio-queue

    2024年02月13日
    浏览(34)
  • Windows安装Stable Diffusion ComfyUI及问题解决记录(注意不是Stable Diffusion WebUI)

    本文是 Stable Diffusion ComfyUI 的安装介绍,并非Stable Diffusion WebUI。该软件使用了流程管理,目前来看更适合专业的设计师,虽然已能实现所有原生的功能,但软件本身目前仍处于初级阶段,还有很多地方需要改进,比如中文版、更多的扩展…的支持~~所以如果你对stable diffusion还

    2024年02月09日
    浏览(32)
  • Windows安装Stable Diffusion WebUI及问题解决记录

    本文将详细介绍stable diffusion webui的下载、安装及问题解决。 StableDiffusion是2022年发布的深度学习文本到图像生成模型。它主要用于根据文本的描述产生详细图像,尽管它也可以应用于其他任务,如内补绘制、外补绘制,以及在提示词​(英语)指导下产生图生图的翻译。它是

    2024年02月02日
    浏览(31)
  • 记录安装stable diffusion webui时,出现的gfpgan安装卡住的问题

    参考链接:(145条消息) 使用stable diffusion webui时,安装gfpgan失败的解决方案(windows下的操作)_新时代原始人的博客-CSDN博客  

    2024年02月16日
    浏览(29)
  • 树莓派-python3.11 记录opencv 安装过程遇到问题

    按照这一篇进行树莓派4b安装opencv-python详细过程。 方法一:大通过编译安装,其中会遇到不少问题,之前安装过一遍走通过一次,但是python版本高了之后遇到很多问题。目前没走通,给出解决方案以供参考。  在4.配置cmake时遇到第一个问题, 这段代码会显示如下的报错:

    2024年02月03日
    浏览(38)
  • stable diffusion官方版本复现

    踩了一些坑,来记录下 CentOS Linux release 7.5.1804 (Core) 服务器 RTX 3090 按照Stable Diffusion的readme下载模型权重、我下载的是stable-diffusion-v1-4 版本的 1 因为服务器没法上huggingface,所以得把权重下载到本地,但是运行链接 ln -s path/to/model.ckpt models/ldm/stable-diffusion-v1/model.ckpt 时会报错,

    2024年02月21日
    浏览(22)
  • Stable-diffusion复现笔记

    目前正在学习有关扩撒模型的相关知识,最近复现了Stable-diffuison,此文主要是想记录一下整体的复现过程以及我在复现过程中出现的一些奇怪的问题以及我的处理方法。这里我的复现主要是针对官网文档实现的,并没有用到webui版本,如果是想体验Stable-diffusion可以去下载we

    2024年04月09日
    浏览(47)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包