Featured image of post 【免費・超簡單】使用Stable Diffusion生成式AI插畫圖片的方法!Google Colab步驟解說

【免費・超簡單】使用Stable Diffusion生成式AI插畫圖片的方法!Google Colab步驟解說

想不想試試使用能從輸入文字生成高品質圖片的AI「Stable Diffusion」,來創作您喜歡的插畫呢?本文將為您清楚解說,只需透過Google Colab與免費帳號,任何人都能輕鬆開始生成式AI圖片的步驟。

什麼是 Stable diffusion

Stable diffusion 是由德國慕尼黑大學研究團隊開發的,一種根據輸入文字資訊生成圖像的 AI。 透過讓它學習各種圖像,它可以生成從寫實照片到插圖等各式各樣的圖片。

這次,我將介紹如何使用 Stable diffusion 的預訓練資料來生成插圖。

需要準備的東西

  • Google 帳號

僅此而已

生成步驟

  1. 打開 https://colab.research.google.com
  2. 從左上角的 檔案 中選擇 新增筆記本
  3. 編輯 中選擇 筆記本設定
  4. 硬體加速器 更改為 GPU img_2.png
  5. 貼上並執行以下程式碼
1
!pip install diffusers==0.8.0 transformers
  1. 貼上並執行以下程式碼
1
from diffusers import StableDiffusionPipeline
  1. 貼上並執行以下程式碼
1
2
pipe = StableDiffusionPipeline.from_pretrained("gsdf/Counterfeit-V2.5")
pipe.to("cuda")
  1. 貼上並執行以下程式碼
1
2
3
4
5
prompt = "((masterpiece,best quality)),1girl, solo, animal ears, rabbit, barefoot, knees up, dress, sitting, rabbit ears, short sleeves, looking at viewer, grass, short hair, smile, white hair, puffy sleeves, outdoors, puffy short sleeves, bangs, on ground, full body, animal, white dress, sunlight, brown eyes, dappled sunlight, day, depth of field"
n_prompt = "EasyNegative, extra fingers,fewer fingers"

image = pipe(prompt, negative_prompt = n_prompt).images[0]
image

這裡使用的 Prompt 參考了 https://huggingface.co/gsdf/Counterfeit-V2.5Prompt

生成結果(部分)

img_1.png

img_3.png

img_4.png

參考

comments powered by Disqus