stable diffusion webui和kohya_ss部署:基于conda虚拟环境部署及训练

本文详细介绍了如何在Linux环境下部署stablediffusion-webui的1.8.0版本,以及在Kohya_ss环境中进行环境配置、运行程序、训练模型并处理常见错误的过程。
摘要由CSDN通过智能技术生成

stable diffusion webui环境部署

快速安装stable-diffusion-webui的1.8.0版本的命令行如下所示,推荐linux,否则xformers安装比较麻烦

> conda create -n sdwebui python=3.10
> conda activate sdwebui
> conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=11.8 -c pytorch -c nvidia
> git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git  # 自定义下载路径,可自行下载1.8.0版本源码
> cd stable-diffusion-webui
> pip install -r requirements.txt
> python launch.py  # 会自动下载一些相关库和大模型,需要连接外网,或者提前下载好

使用conda虚拟环境部署stable diffusion webui的教程参见知乎链接 ,其核心是在虚拟环境中pip install -r requirements.txt,而不是运行webui-user.bat(否则会新建一个venv环境),环境和包都配置好之后运行launch.py(会下载一些大模型,可提前下载好)。

kohya_ss环境部署

1. 环境部署

  • 创建虚拟环境

    conda create -n env_kohya_ss python==3.10.0
    
       
       
    • 1
  • 进入虚拟环境

    conda activate env_kohya_ss
    
       
       
    • 1
  • clone源码

    git clone https://github.com/bmaltais/kohya_ss.git
    
       
       
    • 1
  • 进入项目根目录

    cd kohya_ss
    
       
       
    • 1
  • 安装相关库

    # 根据环境选择
    pip install -r requirements_linux.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
    pip install -r requirements_windows_torch2.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
    
       
       
    • 1
    • 2
    • 3

2.运行程序

./gui.sh  --listen 127.0.0.1 --server_port 7860 --inbrowser --share 

 
 
  • 1

3.训练模型参数

  • 根据自己的数据,在有底模的情况下,训练微调模型参数,更好的达到效果

3.1 创建输出文件夹

  • 在根目录创建output/train文件夹
  • 进入output/train文件夹
  • 创建输出相关文件夹models,logs
    在这里插入图片描述

3.2 数据集格式

  • 数据集格式:一张图片对应一个文本且名称相同
  • 数据集存放路径dataset/100_dataset
    kohya_ss/dataset
    kohya_ss/dataset/100_dataset  # 100_dataset数据集文件夹,100_表示训练的批次
    
       
       
    • 1
    • 2
    在这里插入图片描述

3.3 lora模型微调

3.3.1 数据及相关路径
  • input image folder:训练数据集路径为父级路径
    kohya_ss/dataset
    
       
       
    • 1
  • output file path
    # output_models: 输出训练底模路径
    kohya_ss/output/train/models
    # output_logs:输出训练日志路径
    kohya_ss/output/train/logs	
    # prompt :good,得到的底模名称
    
       
       
    • 1
    • 2
    • 3
    • 4
    • 5

在这里插入图片描述

3.3.2 修改超参数
  • 根据自己的需求修改
    • Presets,LoRA type 需选择与lora相关的
      在这里插入图片描述
3.3.3 选择微调的底模

在这里插入图片描述

3.4 sdxl模型微调

3.4.1 数据及相关路径
  • input image folder:训练数据集路径为父级路径
    kohya_ss/dataset
    
       
       
    • 1
  • output file path
    # output_models: 输出训练底模路径
    kohya_ss/output/train/models
    # output_logs:输出训练日志路径
    kohya_ss/output/train/logs	
    # prompt :good,得到的底模名称
    
       
       
    • 1
    • 2
    • 3
    • 4
    • 5

在这里插入图片描述

3.4.2 修改超参数
  • 根据自己的需求修改
    • Presets,LoRA type 需选择与sdxl相关的
      在这里插入图片描述
3.4.3 选择微调的底模
  • 需要选择SDXL Model
    在这里插入图片描述

4. 报错信息

4.1 报错1

  • ImportError: cannot import name 'StableDiffusionXLPipeline' from 'diffusers'
    在这里插入图片描述
    • 解决diffusers0.16.1版本改为0.18.2
      pip uninstall diffusers
      pip uninstall diffusers==0.18.2
      
           
           
      • 1
      • 2

4.2 报错2

  • StableDiffusionXLPipeline requires the invisible-watermark library but it was not found in your environment. You can install it with pip: pip install invisible-watermark>=2.0
    在这里插入图片描述
  • 解决
    pip install invisible-watermark>=2.0
    
       
       
    • 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值