被 AIGC 浪潮一遍遍的拍打,Midjourney 免費的 25 張還沒能讓我學會 “魔法咒語”,沒有外幣結算的信用卡,充值太麻煩了;所以又到了感謝開源萬歲的時候了,繼續 stable-diffusion 練習魔法咒語;Apple 的 M 系列芯片有強大的算力,結合統一內存的技術,我們可以在 M 系列的 Mac 上玩轉 SD,當然,前提是至少得 16G 內存哦!
本著命令行能不用就不用的原則,選擇https://github.com/AUTOMATIC1111/stable-diffusion-webui 開源項目來折騰,並且整個搭建的流程非常自動化;對 Apple 的 ARM 芯片的自動安裝腳本。
基礎環境準備#
你需要有 python、rust 等基礎的運行環境,如果已經安裝 homebrew, 可以使用下面這條命令安裝:
brew install cmake protobuf rust [email protected] git wget
下載項目#
首先進這個項目地址:https://github.com/AUTOMATIC1111/stable-diffusion-webui
如果會使用 git,你可以直接 clone 項目;
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
不會也沒事兒,你可以直接下載項目代碼的壓縮包;
[https://github.com/AUTOMATIC1111/stable-diffusion-webui/archive/refs/heads/master.zip](https://github.com/AUTOMATIC1111/stable-diffusion-webui/archive/refs/heads/master.zip)
下載模型#
項目代碼中是不包含模型的,需要額外去 官方模型庫 或者Hugging Face 下載大佬們訓練好的模型,圖像生成的模型大小一般都挺大,網絡不好下載需要一些時間;
一些受歡迎的官方穩定模型:
- Stable DIffusion 1.4 穩定擴散 1.4 (sd-v1-4.ckptSd-v1-4. ckpt)
- Stable Diffusion 1.5 穩定擴散 1.5 (v1-5-pruned-emaonly.ckptV1-5-pruned-emaonly. ckpt)
- Stable Diffusion 1.5 Inpainting 穩定擴散 1.5 修補 (sd-v1-5-inpainting.ckptSd-v1-5 - 內繪. ckpt)
Hugging Face 中你選擇 Text-to-Image 可以查找受歡迎的模型
最後,將下載好的模型,放在剛剛項目的這個目錄下
stable-diffusion-webui/models/Stable-diffusion
Let's begin#
進入項目根目錄的終端,執行下面代碼,等待運行提示完成,即可在瀏覽器訪問127.0.0.1:7860開始魔法啦;
./webui.sh
在 txt2img 菜單下,輸入你的魔法咒語就可以開始啦;下面各項屬性可以調整生成圖片的分辨率、、數量等等;我們會在後面的文章中來學習該怎麼玩;(我也得學習一下,有點複雜,哈哈哈哈)
關於體驗#
關於生成圖像的速度,基於我的 MacBookPro M1 Pro 32G 的體驗來看,512 分辨率的圖像速度還是挺快的,一般在 15s 以內可以完成;當然隨著你 Sampling steps、批量生成數量的增加時間也會增加;玩了大概半小時,可以摸到 MBP 的溫度升上來了。
官方在 Apple ARM 上使用問題有一些情況說明;目前我使用中還沒有遇到(主要是一些高級玩法還沒使用)
Currently most functionality in the web UI works correctly on macOS, with the most notable exceptions being CLIP interrogator and training. Although training does seem to work, it is incredibly slow and consumes an excessive amount of memory. CLIP interrogator can be used but it doesn't work correctly with the GPU acceleration macOS uses so the default configuration will run it entirely via CPU (which is slow).
Most samplers are known to work with the only exception being the PLMS sampler when using the Stable Diffusion 2.0 model. Generated images with GPU acceleration on macOS should usually match or almost match generated images on CPU with the same settings and seed.
目前,Web UI 中的大多數功能在 macOS 上都能正常工作,最顯著的例外是 CLIP 詢問器和訓練。雖然訓練似乎可以工作,但速度非常慢,並且消耗過多的內存。CLIP 詢問器可以使用,但它不能正確地與 macOS 使用的 GPU 加速配合使用,因此默認配置將完全通過 CPU 運行(這很慢)。
大多數採樣器都已知可用,唯一的例外是在使用 Stable Diffusion 2.0 模型時使用 PLMS 採樣器。在 macOS 上啟用 GPU 加速生成圖像應該通常與相同設置和種子下 CPU 生成圖像匹配或幾乎匹配。
後續#
近期,我想要用 AIGC 幫我生成好看的 Logo,沒有美術設計背景畫的 Logo 真的慘不忍睹;後續我也會將過程實踐中學到的使用教程整理分享出來,之後見啦!
參考來源: