经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Docker » 查看文章
基于Docker安装的Stable Diffusion使用CPU进行AI绘画
来源:cnblogs  作者:七仔的博客  时间:2023/2/1 9:36:37  对本文有异议

基于Docker安装的Stable Diffusion使用CPU进行AI绘画

  • 由于博主的电脑是为了敲代码考虑买的,所以专门买的高U低显,i9配核显,用Stable Diffusion进行AI绘画的话倒是专门有个CPU模式,不过安装过程经历了许多坎坷,特此记录一下

  • 博主的环境是Windows 11附带的WSL2中安装的Ubuntu 20.04 LTS,安装的Stable Diffusion Docker版本为2.1.0

安装条件

  1. 安装Docker
  2. 安装DockerCompose
  3. 会Docker(博主说的比较粗略,不建议没有docker经验的按本博客进行)

一、下载代码

地址:https://github.com/AbdBarho/stable-diffusion-webui-docker/archive/refs/tags/2.1.0.zip

解压到你需要的路径

二、修改路径

wsl2对应windows的路径如: D:/soft --> /mnt/d/soft

在你上个解压的文件里面的docker-compose.yml中更改路径

  1. 例如build: ./services/download/
  2. 改为
  3. build: /mnt/d/wsl/stable-diffusion-webui/stable-diffusion-webui-docker-2.1.0/services/download/

三、构建下载

命令为

  1. docker compose --profile download up --build

四、构建镜像

  1. 主要的坑也是这里了,需要修改service/AUTOMATIC1111/Dockerfile,修改为下方代码

博主删除了不必要的xformers(必须要google drive,而且开了代理也不行,cpu模式不需要这个东西),然后对git加了代理,然后修改了git的配置

  1. # syntax=docker/dockerfile:1
  2. FROM alpine/git:2.36.2 as download
  3. SHELL ["/bin/sh", "-ceuxo", "pipefail"]
  4. RUN git config --global http.version HTTP/1.1
  5. RUN git config --global http.postBuffer 524288000
  6. RUN git config --global https.postBuffer 524288000
  7. RUN git config --global core.compression -1
  8. RUN git clone https://github.91chi.fun/https://github.com/salesforce/BLIP.git repositories/BLIP && cd repositories/BLIP && git reset --hard 48211a1594f1321b00f14c9f7a5b4813144b2fb9
  9. RUN git clone https://github.91chi.fun/https://github.com/sczhou/CodeFormer.git repositories/CodeFormer && cd repositories/CodeFormer && git reset --hard c5b4593074ba6214284d6acd5f1719b6c5d739af
  10. RUN git clone https://github.91chi.fun/https://github.com/CompVis/stable-diffusion.git repositories/stable-diffusion && cd repositories/stable-diffusion && git reset --hard 69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc
  11. RUN <<EOF
  12. # because taming-transformers is huge
  13. git config --global http.postBuffer 1048576000
  14. git clone https://github.91chi.fun/https://github.com/CompVis/taming-transformers.git repositories/taming-transformers
  15. cd repositories/taming-transformers
  16. git reset --hard 24268930bf1dce879235a7fddd0b2355b84d7ea6
  17. rm -rf data assets
  18. EOF
  19. RUN git clone https://github.91chi.fun/https://github.com/crowsonkb/k-diffusion.git repositories/k-diffusion && cd repositories/k-diffusion && git reset --hard f4e99857772fc3a126ba886aadf795a332774878
  20. FROM python:3.10-slim
  21. SHELL ["/bin/bash", "-ceuxo", "pipefail"]
  22. ENV DEBIAN_FRONTEND=noninteractive PIP_PREFER_BINARY=1 PIP_NO_CACHE_DIR=1
  23. RUN pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113
  24. RUN apt-get update && apt install fonts-dejavu-core rsync git -y && apt-get clean
  25. RUN <<EOF
  26. git clone https://github.91chi.fun/https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
  27. cd stable-diffusion-webui
  28. git reset --hard 1eb588cbf19924333b88beaa1ac0041904966640
  29. pip install -r requirements_versions.txt
  30. EOF
  31. ENV ROOT=/stable-diffusion-webui WORKDIR=/stable-diffusion-webui/repositories/stable-diffusion
  32. COPY --from=download /git/ ${ROOT}
  33. RUN pip install --prefer-binary --no-cache-dir -r ${ROOT}/repositories/CodeFormer/requirements.txt
  34. # TODO: move to top
  35. RUN apt-get install jq moreutils -y
  36. # Note: don't update the sha of previous versions because the install will take forever
  37. # instead, update the repo state in a later step
  38. ARG SHA=36a0ba357ab0742c3c4a28437b68fb29a235afbe
  39. RUN <<EOF
  40. cd stable-diffusion-webui
  41. git pull --rebase
  42. git reset --hard ${SHA}
  43. pip install --prefer-binary --no-cache-dir -r requirements_versions.txt
  44. EOF
  45. RUN pip install --prefer-binary --no-cache-dir opencv-python-headless git+https://github.91chi.fun/https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 git+https://github.91chi.fun/https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1 pyngrok
  46. COPY . /docker
  47. RUN <<EOF
  48. chmod +x /docker/mount.sh && python3 /docker/info.py ${ROOT}/modules/ui.py
  49. EOF
  50. ENV CLI_ARGS=""
  51. WORKDIR ${WORKDIR}
  52. EXPOSE 7860
  53. # run, -u to not buffer stdout / stderr
  54. CMD /docker/mount.sh && python3 -u ../../webui.py --listen --port 7860 --ckpt-dir ${ROOT}/models/Stable-diffusion ${CLI_ARGS}
  1. 修改以后运行
  1. docker compose --profile auto-cpu up --build

结果

放下测试的结果(一个奇奇怪怪的小猫)

AI绘画小猫

AI绘画的小猫

AI绘画的风景

原文链接:https://www.cnblogs.com/baby7/p/docker_cpu_stable_diffusion.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号