AI绘画之Disco-diffusion试坑指南
一.硬件说明
CUDA:N卡 8G显存以上 运行内存12G以上 虚拟内存10G以上 硬盘30G以上
CPU: 运行内存12G以上 虚拟内存10G以上 硬盘30G以上(最好固态硬盘)
二.软件说明
主体包 https://github.com/alembics/disco-diffusion 克隆或下载最新版,运行主目录
辅助包 https://files.botbox.dev/discoAI/download/main.zip 或
https://github.com/mazzzystar/disco-diffusion-wrapper
和主体包放一起
三.前提条件
提前装好Python、Git
N卡驱动 CUDA(11版本以上) CUDNN 三者要互相兼容(CPU版跳过)
https://developer.nvidia.com/cuda-toolkit 根据自身显卡驱动下载对应版本
https://developer.nvidia.com/cudnn 下载好解压缩,拷贝到你CUDA安装的版本号目录下
安装torch和torchvision,要求CUDA11以上版本,如果想CPU玩就选择CPU版本
https://download.pytorch.org/whl/torch_stable.html 根据自身要求自行下载
最好添加下系统环境变量
四.运行环境
Python -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ 安装系统环境,后边的是清华源,可自己换镜像源
也可以安装VS code或者PyCharm等新建项目运行Disco_Diffusion.ipynb,安装环境
Python main.py 会自动安装一些模型,装好后只能命令行玩,需要手动修改main.py调画图参数
手动下载
pip install 和 git clone 报错缺啥下啥
disco-diffusion https://github.com/alembics/disco-diffusion 放根目录
CLIP https://github.com/openai/CLIP 放根目录
SLIP https://github.com/facebookresearch/SLIP 放根目录
guided-diffusion https://github.com/crowsonkb/guided-diffusion 放根目录
ResizeRight https://github.com/assafshocher/ResizeRight 放根目录
pytorch3d-lite https://github.com/MSFTserver/pytorch3d-lite 放根目录
MiDaS https://github.com/isl-org/MiDaS 放根目录
Pretrained Release v0.1.0 · mazzzystar/disco-diffusion-wrapper · GitHub 根目录下Pretrained /AdaBins_nyu.pt
五.模型下载
256x256_diffusion_uncond.pt 放content文件夹
https://openaipublic.blob.core.windows.net/diffusion/jul-2021/256x256_diffusion_uncond.pt
512x512_diffusion_uncond_finetune_008100.pt 放content文件夹
http://batbot.tv/ai/models/guided-diffusion/512x512_diffusion_uncond_finetune_008100.pt
secondary_model_imagenet_2.pth 放content文件夹
https://v-diffusion.s3.us-west-2.amazonaws.com/secondary_model_imagenet_2.pth
CLIP模型目录
main.py 缓存在deploy\.cache\clip下
disco.py 缓存在默认路径 ~\.cache\clip下,位于用户名根目录下
修改clip缓存路径,修改 PATHON 下 CLIP包 clip.py ,默认为None
def load(name: str, device: Union[str, torch.device] = "cuda" if torch.cuda.is_available() else "cpu", jit: bool = False, download_root: str = None):
模型文件
main.py 在content目录下
disco.py 在models目录下
或者修改运行文件
initDirPath = f'F:/AI/AI-DRAW/stable-diffusion-webui/outputs' 输入图片文件夹路径
outDirPath = f'F:/AI/AI-DRAW/stable-diffusion-webui/outputs/disco-diffusion/images_out' 输出文件夹路径
root_path 运行文件目录,默认就好
model_path 模型文件目录
sys.path.append('./CLIP')
sys.path.append('./guided-diffusion')
sys.path.append('./SLIP')
sys.path.append('./ResizeRight')
Python disco_xform_utils.py
六.报错参考
1. No module named 'py3d_tools'
修改pytorch3d-lite文件夹名为pytorch3d_lite
修改disco_xform_utils.py
import py3d_tools as p3d 为
import pytorch3d_lite.py3d_tools as p3d
修改disco.py
pytorch3d-lite 为
pytorch3d_lite (可记事本模式全部替换)
2.No module named 'midas_utils'
修改disco_xform_utils.py中
import midas_utils 为
from MiDaS import midas_utils
3.No module named 'infer'
修改disco_xform_utils.py中
from infer import InferenceHelper 为
from AdaBins.infer import InferenceHelper
4.No module named 'model_io'
修改AdaBins\infer.py中
import model_io 为
import AdaBins.model_io
5.No module named 'utils'
修改AdaBins\infer.py中
import utils 为
import AdaBins.utils
6.ImportError: cannot import name 'UnetAdaptiveBins' from 'models' (unknown location)
修改AdaBins\infer.py中
from models import UnetAdaptiveBins 为
from AdaBins.models import UnetAdaptiveBins
Python disco.py
CPU运行需修改运行py文件
useCPU = False 为
useCPU = True
无则添加
useCPU = True
搜索import torch 修改为
DEVICE = torch.device('cuda:0' if (torch.cuda.is_available() and not useCPU) else 'cpu')
print('Using device:', DEVICE)
device = DEVICE # At least one of the modules expects this name..
if not useCPU:
if torch.cuda.get_device_capability(DEVICE) == (8,0): ## A100 fix thanks to Emad
print('Disabling CUDNN for A100 gpu', file=sys.stderr)
torch.backends.cudnn.enabled = False
在model_config = model_and_diffusion_defaults() 后添加
fp16 = True
if useCPU:
fp16 = False
替换'use_fp16': True, 为
'use_fp16': not useCPU,
7.ECC features not supported for GPU 00000000:01:00.0.
Treating as warning and moving on.
All done.
Google Colab not detected.
要等一会
Disco_Diffusion.py
Disco_Diffusion.ipynb转换而来
jupyter nbconvert --to script Disco_Diffusion.ipynb 转换代码
8.TypeError: GaussianDiffusion.ddim_sample_loop_progressive() got an unexpected keyword argument 'transformation_fn'
修改报错2的Diffusion and CLIP model settings的
diffusion_sampling_mode = ' ddim ' #@param ['plms','ddim'] 为
diffusion_sampling_mode = 'plms' #@param ['plms','ddim']
9. AttributeError: 'SpacedDiffusion' object has no attribute 'plms_sample_loop_progressive'. Did you mean: 'p_sample_loop_progressive'?
修改报错行 plms_sample_loop_progressive 为 p_sample_loop_progressive
10. TypeError: GaussianDiffusion.p_sample_loop_progressive() got an unexpected keyword argument 'order'
修改报错行参数
把 order=2, 删掉或者注释掉
# order=2,
七.参数设置
搜索 Settings
文生图
图片参数 steps 生成步数,建议100步以上
width_height 分辨率,必须是64的倍数,建议图不要太小,容易糊,
同时注意太大会爆显存,而且速度慢,建议512--1024
cutn_batches 图片变化梯度,越高生成越慢,越不容易糊 建议4
n_batches 和 batch_size 一次出图数量,建议都调成1
text_prompts = [ ] 文本输入框
image_prompts = [ ] 参考图片输入地址
八.输入设置
直接修改你需要启动的py文件
修改你需启动的py文件,命令行输入
steps=int(input("请输入迭代次数1-1000:"))
width_height[0]=int(input("请输入64整数倍宽:"))
width_height[1]=int(input("请输入64整数倍高:"))
cutn_batches=int(input("请输入图片梯度参数1-8:"))
text_prompts=input("输入你想生成的图片描述:")
UI浏览器登录需要魔改参数,比较麻烦,就不赘叙了
九.生成图片


