Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sd webui #39

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
sources/timm/index.rst
sources/Diffusers/index.rst
sources/opencv/index.rst
sources/sd_webui/index.rst

.. warning::

Expand Down Expand Up @@ -145,9 +146,9 @@
<div class="flex space-x-4 text-blue-600">
<a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui">官方链接</a>
<span class="split">|</span>
<a href="#">安装指南</a>
<a href="sources/sd_webui/install.html">安装指南</a>
<span class="split">|</span>
<a href="#">快速上手</a>
<a href="sources/sd_webui/quick_start.html">快速上手</a>
</div>
</div>
<!-- Card 7 -->
Expand Down
Binary file added sources/sd_webui/images/cat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sources/sd_webui/images/catwearhat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sources/sd_webui/images/mainparameters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sources/sd_webui/images/moreparameters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions sources/sd_webui/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Stable-Diffusion-WebUI
==================

.. toctree::
:maxdepth: 2

install.rst
quick_start.rst
76 changes: 76 additions & 0 deletions sources/sd_webui/install.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
安装指南
==================

本文面向昇腾开发者,帮助开发者完成stable-diffusion-webui在昇腾上的安装

.. note::

请确保环境安装了对应的固件和驱动,详情请参考 `快速安装昇腾环境 <../ascend/quick_install.html>`_。


安装miniconda
----------------

.. code-block:: shell
:linenos:

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh

使用conda创建环境
---------------------

.. code-block:: shell
:linenos:

conda create -n python310 python=3.10.6
conda activate python310

安装stable-diffusion-webui
----------------------------------

- 自动安装命令如下:

.. code-block:: shell
:linenos:

git clone --branch dev https://github.com/AUTOMATIC1111/stable-diffusion-webui.gitcd stable-diffusion-webui

#此命令将在首次安装时自动在 Ascend 设备上安装 torch 和 torch_npu。
./webui.sh --listen --skip-torch-cuda-test --no-half


- 手动安装:

.. code-block:: shell
:linenos:

# install stable-diffusion-webui
git clone --branch dev https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui
python -m venv venv
source ./venv/bin/activate
pip install torch==2.1.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install torch_npu==2.1.0
pip install https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip --prefer-binary
pip install https://github.com/mlfoundations/open_clip/archive/bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b.zip
pip install -U -I --no-deps xformers==0.0.23.post1
pip install install ngrok
mkdir repositories
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets.git stable-diffusion-webui-assets
git -C stable-diffusion-webui-assets checkout 6f7db241d2f8ba7457bac5ca9753331f0c266917
git clone https://github.com/Stability-AI/stablediffusion.git stable-diffusion-stability-ai
git -C stable-diffusion-stability-ai checkout cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf
git clone https://github.com/Stability-AI/generative-models.git generative-models
git -C generative-models checkout 45c443b316737a4ab6e40413d7794a7f5657c19f
git clone https://github.com/crowsonkb/k-diffusion.git k-diffusion
git -C k-diffusion checkout ab527a9a6d347f364e3d185ba6d714e22d80cb3c
git clone https://github.com/salesforce/BLIP.git BLIP
git -C BLIP checkout 48211a1594f1321b00f14c9f7a5b4813144b2fb9
pip install -r requirements.txt
pip install -r requirements_npu.txt

94 changes: 94 additions & 0 deletions sources/sd_webui/quick_start.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
快速开始
============

.. note::

阅读本篇前,请确保已按照 :doc:`安装指南 <./install>` 准备好昇腾环境及stable-diffusion-webui!


参数说明
---------------

主要参数
<<<<<<<<<<<<<<

.. figure:: ./images/mainparameters.png
:align: center

- Stable Diffusion checkpoint

用于更换模型文件,v1-5-pruned-emaonly.safetensors为stable-diffusion-webui的默认模型文件,更换其他模型文件需自行下载。

- Prompt

正面提示词,构成提示词的基础,直接描述想要生成的图像内容、风格、情感等作为元素权重的关键词,让AI更倾向于在绘图中绘制和Prompt的内容相关的元素。

- Negative Prompt

反向提示词,作用与Prompt相反,反向加权的权重关系,减少某些元素出现的频率,从而约束AI的行为。

- Generate

即开始生成图片按钮。

其他参数
<<<<<<<<<<<<<<<<

.. figure:: ./images/moreparameters.png
:align: center

- Sampling method

即采样方法,采样方法本身并没有绝对意义上的优劣之分,只有是否合适这一说:

+ Euler方法,是比较成熟的一种采样方法,效果比较稳定

+ LMS:这个是最小均方误差算法,这是一个自适应的滤波器。

+ Heun:这个是建立在欧拉方法基础上的一个在给定初始条件下求解常微分方程的方法。

+ DPM:这是一个深度学习的PDE(偏微分方程)增强方法。

- Sampling Steps

即采样步长,它并不是越大越好,同样也不是越小越好,太小采样的随机性会很高,太大采样的效率会很低,拒绝概率高。

- seed

seed即为种子,-1时生成一个随机数,这个随机数影响画面的内容,相当于手动初始了神经网络的权重参数,在配合其他相同参数的情况下能得到一个极其类似的结果。

- Width & Height

生成图片的宽和高

文生图
-----------------

文生图就是根据文字生成图片,主要操作为点击Stable Diffusion checkpoint选择模型,在Prompt和Negative Prompt填入提示词,点击Generate按钮生成图片。

以下是根据提示词生成的图片:

Prompt:a cute cat

Negative Prompt:deformed, lowres, bad anatomy

.. figure:: ./images/cat.png
:align: center

图生图
--------------------

图生图(img2img)是让AI参照现有的图片生图:

如上传一张真人照片,让AI把他改绘成动漫人物;上传画作线稿,让AI自动上色;上传一张黑白照,让AI把它修复成彩色相片。

参数和操作与文生图重叠,这里不在赘述。

以下是图片生成的效果:

Prompt:a cute cat wear a hat

Negative Prompt:deformed, lowres, bad anatomy

.. figure:: ./images/catwearhat.png
:align: center