电商网站合作,3 建设营销型网站流程,做网站网页版和手机版,地方网站盈利模式前排提示#xff1a;如果不想折腾#xff0c;可直接跳到最后获取封装好的容器#xff0c;一键运行 :D 前言
乘上AI生成的快车#xff0c;一同看看沿途的风景。
启一个miniconda容器
docker run -itd -v 宿主机内SD项目路径:/tmp --gpus all --ipc host -p 7860:7860 con…
前排提示如果不想折腾可直接跳到最后获取封装好的容器一键运行 :D 前言
乘上AI生成的快车一同看看沿途的风景。
启一个miniconda容器
docker run -itd -v 宿主机内SD项目路径:/tmp --gpus all --ipc host -p 7860:7860 continuumio/miniconda3:latest
打开容器
docker exec -it 容器id bash
cd /tmp 下载项目代码
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
注如果搭了梯子也无法 git clone可以直接下载 项目.zip 文件然后在本地解压。 安装依赖
先安装 torch和更新setuptools不然在使用pip安装basicsr库的时候卡住在Preparing metadata (setup.py)。
pip install --upgrade pip setuptools wheel
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/你的cuda版本比如:cu121
上面的 index-url 参考 pytorch 官方
Start Locally | PyTorch 使用清华源安装 requirements_versions.txt
pip install -r requirements_versions.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
使用阿里源安装 requirements.txt
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
注清华源安装 requirements.txt 会出现报错 Preparing metadata (setup.py) ... errorerror: subprocess-exited-with-error× python setup.py egg_info did not run successfully.│ exit code: 1╰─ [26 lines of output]Traceback (most recent call last):File /tmp/pip-install-_h0cg0e2/basicsr_f6e24d42eda94c67800f8a48e46b0e6a/setup.py, line 50, in get_hashfrom basicsr.version import __version__File /tmp/pip-install-_h0cg0e2/basicsr_f6e24d42eda94c67800f8a48e46b0e6a/basicsr/__init__.py, line 3, in modulefrom .archs import *File /tmp/pip-install-_h0cg0e2/basicsr_f6e24d42eda94c67800f8a48e46b0e6a/basicsr/archs/__init__.py, line 5, in modulefrom basicsr.utils import get_root_logger, scandirFile /tmp/pip-install-_h0cg0e2/basicsr_f6e24d42eda94c67800f8a48e46b0e6a/basicsr/utils/__init__.py, line 3, in modulefrom .img_process_util import USMSharp, usm_sharpFile /tmp/pip-install-_h0cg0e2/basicsr_f6e24d42eda94c67800f8a48e46b0e6a/basicsr/utils/img_process_util.py, line 1, in moduleimport cv2ModuleNotFoundError: No module named cv2During handling of the above exception, another exception occurred:Traceback (most recent call last):File string, line 2, in moduleFile pip-setuptools-caller, line 34, in moduleFile /tmp/pip-install-_h0cg0e2/basicsr_f6e24d42eda94c67800f8a48e46b0e6a/setup.py, line 139, in modulewrite_version_py()File /tmp/pip-install-_h0cg0e2/basicsr_f6e24d42eda94c67800f8a48e46b0e6a/setup.py, line 67, in write_version_pysha get_hash()^^^^^^^^^^File /tmp/pip-install-_h0cg0e2/basicsr_f6e24d42eda94c67800f8a48e46b0e6a/setup.py, line 53, in get_hashraise ImportError(Unable to get git version)ImportError: Unable to get git version[end of output]note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed× Encountered error while generating package metadata.
╰─ See above for output.note: This is an issue with the package mentioned above, not pip.
hint: See above for details. 下载模型
推荐在 Hugging Face 下载模型文件
Stable Diffusion 2.1 版本https://huggingface.co/stabilityai/stable-diffusion-2-1/tree/main 把文件下载到本地需要登录后才能下载 注如果网络不好可以选择网盘地址如果失效和我联系 :D。
最后把下载到的模型文件放到./models/Stable-diffusion下。 运行 webui.py
打开 ./modules/launch_utils.py添加https://ghproxy.com/到def prepare_environment函数中的如下位置 清空 ./repositories 文件夹内的所有文件如果为空可忽略然后依次执行顺序不要错
git clone https://github.com/Stability-AI/stablediffusion.git repositories/stable-diffusion-stability-ai
git clone https://github.com/crowsonkb/k-diffusion.git repositories/k-diffusion
git clone https://github.com/salesforce/BLIP.git repositories/BLIP
git clone https://github.com/sczhou/CodeFormer.git repositories/CodeFormer
运行 webui.py
可能的报错ImportError: libGL.so.1: cannot open shared object file: No such file or directory
解决
pip install opencv-python-headless 可能使用wsl2的同学会遇到一个问题宿主机无法打开 127.0.0.1:7860。
原因参考使用 WSL 访问网络应用程序
参数对应代码
modules/cmd_args.py里
parser.add_argument(--listen, actionstore_true, helplaunch gradio with 0.0.0.0 as server name, allowing to respond to network requests)
webui.py里
api.launch(server_name0.0.0.0 if cmd_opts.listen else 127.0.0.1,...
)
注1 对于同一个局域网下不在宿主机上直接打开网页的同学可以在你的主机浏览器里输入
宿主机ip:7860
注2如果要用CPU推理 :D ) 可能出现报错
RuntimeError: xxx not implemented for Half
解决启动 webui.py 的时候再加上参数 --no-half
注3如果报错 CUDA out of memory
torch.cuda.OutOfMemoryError: CUDA out of memory. {省略一长串}. If reserved but unallocated memory is large try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
解决只需把 PYTORCH_CUDA_ALLOC_CONFmax_split_size_mb:32可以加到系统环境变量里面镜像里我已加上 接下来就可以愉快地生成图片啦 资源消耗
生成图片分辨率设置为768SD 2.0 使用 768*768 分辨率图片训练所得8G显存已经无法满足生成需求因此单张图片生成时间极其缓慢花费31.8s Ubuntu平台因为能使用更多显存3060 12G的生成速度快于 3070 8G其实也可能和WSL性能损耗有关 最后得到一张效果较为不错的照片 标醉里不知天在水满船清梦压星河题 一键运行
对于不想折腾的同学可以直接下载我封装好的镜像网盘地址
打开终端运行如下命令
cd 镜像名称.tar所在的路径
docker load -i wind_Stable_Diffusion_Webui.tar
docker run -it --rm --gpus all --ipc host -p 7860:7860 wind/stable_diffusion_webui:v1
python webui.py
入股一键运行出现报错可参考前面的详细教程。 —End