AI繪畫之Disco-diffusion試坑指南
一.硬件說明
CUDA:N卡 8G顯存以上 ?運行內存12G以上 ?虛擬內存10G以上 ?硬盤30G以上
CPU: 運行內存12G以上 ?虛擬內存10G以上 ?硬盤30G以上(最好固態(tài)硬盤)
二.軟件說明
主體包 ?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? 根據自身要求自行下載
最好添加下系統(tǒng)環(huán)境變量
?四.運行環(huán)境
Python -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/? 安裝系統(tǒng)環(huán)境,后邊的是清華源,可自己換鏡像源
也可以安裝VS code或者PyCharm等新建項目運行Disco_Diffusion.ipynb,安裝環(huán)境
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瀏覽器登錄需要魔改參數,比較麻煩,就不贅敘了
九.生成圖片


