AI Mapping Using Stable Diffusion on Kaggle

foreword

  • Because Stable Diffusionof the need for AI drawing GPU, this limits its application
  • This article describes how to Kaggledeploy in Stable Diffusion, and use the free P100 GPU for inference (30 hours of free use per week), after deployment, you can use it inAny mobile terminaluse.
  • This project stable-diffusion-webui-kaggleis improved on the basis, the original author Github project address
  • Welcome to Copy and Editmy kaggle notebook, project address . Show results
    insert image description here

tutorial

  • First of all, you need to register a Kaggle account. During the registration process, you may need to surf the Internet scientifically . There will be no tutorials here. Please find other tutorials to solve the problem.
  • Create a new one notebookand put the following code into it
import os
import shutil
import subprocess
import threading
import time
import socket

!apt -y update -qq
!apt -y install -qq aria2
!pip install -q torch==1.13.1+cu117 torchvision==0.14.1+cu117 -f https://download.pytorch.org/whl/torch_stable.html
!pip install -q https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.16/xformers-0.0.16+814314d.d20230118-cp38-cp38-linux_x86_64.whl
!pip install -q huggingface-hub==0.11.0 -U

!git clone -b v2.0 https://github.com/camenduru/stable-diffusion-webui
!wget https://raw.githubusercontent.com/camenduru/stable-diffusion-webui-scripts/main/run_n_times.py -O /kaggle/working/stable-diffusion-webui/scripts/run_n_times.py
!git clone https://github.com/AlUlkesh/stable-diffusion-webui-images-browser /kaggle/working/stable-diffusion-webui/extensions/stable-diffusion-webui-images-browser
!git clone https://github.com/camenduru/stable-diffusion-webui-huggingface /kaggle/working/stable-diffusion-webui/extensions/stable-diffusion-webui-huggingface
!git clone -b v2.0 https://github.com/camenduru/sd-civitai-browser /kaggle/working/stable-diffusion-webui/extensions/sd-civitai-browser
!git clone https://github.com/kohya-ss/sd-webui-additional-networks /kaggle/working/stable-diffusion-webui/extensions/sd-webui-additional-networks
!git clone https://github.com/etherealxx/batchlinks-webui /kaggle/working/stable-diffusion-webui/extensions/batchlinks-webui
!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-nsfw-censor /kaggle/working/stable-diffusion-webui/extensions/stable-diffusion-webui-nsfw-censor
%cd /kaggle/working/stable-diffusion-webui

!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/anything-v4.5-vae-swapped/resolve/main/anything-v4.5-vae-swapped.safetensors -d /kaggle/working/stable-diffusion-webui/models/Stable-diffusion -o anything-v4.5-vae-swapped.safetensors

!sed -i -e 's/numpy==1.23.3/numpy==1.21.6/g' requirements_versions.txt
!sed -i -e 's/blendmodes==2022/blendmodes==2021/g' requirements_versions.txt
!sed -i -e 's/fastapi==0.90.1/fastapi==0.89.1/g' requirements_versions.txt
!sed -i -e '''/    prepare_environment()/a\    os.system\(f\"""sed -i -e ''\"s/dict()))/dict())).cuda()/g\"'' /kaggle/working/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/util.py""")''' /kaggle/working/stable-diffusion-webui/launch.py

!npm install -g localtunnel
def iframe_thread(port):
    while True:
        time.sleep(0.5)
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        result = sock.connect_ex(('127.0.0.1', port))
        if result == 0:
            break
        sock.close()
    p = subprocess.Popen(["lt", "--port", "{}".format(port)], stdout=subprocess.PIPE)
    for line in p.stdout:
        print(line.decode(), end='')
threading.Thread(target=iframe_thread, daemon=True, args=(7860,)).start()

# 删除原始模型
os.remove('/kaggle/working/stable-diffusion-webui/models/Stable-diffusion/anything-v4.5-vae-swapped.safetensors')
os.mkdir('/kaggle/working/stable-diffusion-webui/models/Lora')

# 下载GuoFeng3模型
!wget https://civitai.com/api/download/models/36644
# 重命名文件
os.rename("/kaggle/working/stable-diffusion-webui/36644","/kaggle/working/stable-diffusion-webui/GuoFeng3.safetensors")
# 移动至主模型文件夹
shutil.move("/kaggle/working/stable-diffusion-webui/GuoFeng3.safetensors",'/kaggle/working/stable-diffusion-webui/models/Stable-diffusion')

# 下载KoreanDollLikeness_v10
!wget https://civitai.com/api/download/models/22968
# 重命名文件
os.rename("/kaggle/working/stable-diffusion-webui/22968","/kaggle/working/stable-diffusion-webui/koreanDollLikeness_v10.safetensors")
# 移动至主模型文件夹
shutil.move("/kaggle/working/stable-diffusion-webui/koreanDollLikeness_v10.safetensors",'/kaggle/working/stable-diffusion-webui/models/Lora')

!python launch.py --share --xformers --enable-insecure-extension-access --theme dark --gradio-queue
  • Here I deleted the original anything-v4.5-vae-swappedmodel and downloaded GuoFeng3the trunk model and KoreanDollLikenessLora model.
  • The main model is equivalent to the main theme of the picture. For example, GuoFeng3the model is in the gorgeous ancient Chinese style, or it can be said to be an ancient game character.
  • The Lora model is equivalent to fine-tuning a certain part of the backbone model, KoreanDollLikenesswhich mainly adjusts the facial structure. For more specific instructions, you can inquire by yourself.
  • It takes about 5-10 minutes to run the code block after pasting the above code. There may be warnings and errors in the middle, so don’t worry about it, as long as the operation is not terminated (the above code will be available as of May 24, 2023).
  • After deployment, the following link will appear:
Running on local URL:  http://127.0.0.1:7860
your url is: https://rotten-cities-float.loca.lt
Running on public URL: https://7b1114ee-9fb9-42db.gradio.live

This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces
  • Click public URLon the link https://7b1114ee-9fb9-42db.gradio.live, you can enter gradiothe space, not only your computer, anyMobile Internet DevicesIt will be all right.
  • Regarding Stable Diffusion webUIthe use of the game, here is the recommended Bilibili UP master, fish pendulum feeding tutorial, web page address
  • The generated picture can be directly right-clicked in the picture frame and selected to save as, or go back to /kaggle/working/stable-diffusion-webui/outputthe folder in kaggle to download
  • Here are two examples Prompt:
prompt: best quality, masterpiece, highres, 1girl,blush,(seductive smile:0.8),star-shaped pupils,china hanfu,hair ornament,necklace, jewelry,Beautiful face,upon_body, tyndall effect,photorealistic, dark studio, rim lighting, two tone lighting,(high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, volumetric lighting, candid, Photograph, high resolution, 4k, 8k, Bokeh

Negative prompt: (((simple background))),monochrome ,lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, lowres, bad anatomy, bad hands, text, error, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, ugly,pregnant,vore,duplicate,morbid,mut ilated,tran nsexual, hermaphrodite,long neck,mutated hands,poorly drawn hands,poorly drawn face,mutation,deformed,blurry,bad anatomy,bad proportions,malformed limbs,extra limbs,cloned face,disfigured,gross proportions, (((missing arms))),(((missing legs))), (((extra arms))),(((extra legs))),pubic hair, plump,bad legs,error legs,username,blurry,bad feet

Steps: 30, Sampler: Euler a, CFG scale: 9, Seed: 3556647833, Size: 640x1024, Model hash: 4078eb4174, Model: gf_anylora_gf3.2_anylora1.2, Denoising strength: 0, Clip skip: 2, ENSD: 31337, Hires upscale: 2, Hires steps: 64, Hires upscaler: R-ESRGAN 4x+ Anime6B
prompt: <lora:koreanDollLikeness_v10:0.35>,best quality ,masterpiece, illustration, an extremely delicate and beautiful, extremely detailed ,CG ,unity ,8k wallpaper, Amazing, finely detail, masterpiece,best quality,official art,extremely detailed CG unity 8k wallpaper,absurdres, incredibly absurdres, huge filesize , ultra-detailed, highres, extremely detailed,beautiful detailed girl, extremely detailed eyes and face, beautiful detailed eyes,light on face,(Hanfu:1.1),1girl

Negative prompt: sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, bad anatomy,(long hair:1.4),DeepNegative,(fat:1.2),facing away, looking away,tilted head, Multiple people, lowres,bad anatomy,bad hands, text, error, missing fingers,extra digit, fewer digits, cropped, worstquality, low quality, normal quality,jpegartifacts,signature, watermark, username,blurry,bad feet,cropped,poorly drawn hands,poorly drawn face,mutation,deformed,worst quality,low quality,normal quality,jpeg artifacts,signature,watermark,extra fingers,fewer digits,extra limbs,extra arms,extra legs,malformed limbs,fused fingers,too many fingers,long neck,cross-eyed,mutated hands,polar lowres,bad body,bad proportions,gross proportions,text,error,missing fingers,missing arms,missing legs,extra digit, extra arms, extra leg, extra foot,

Steps: 35, Sampler: DPM++ SDE Karras, CFG scale: 7.5, Seed: 4047600339, Size: 672x1056, Model hash: 26d8b87829, Model: BeautyProMix, Variation seed: 1750564158, Variation seed strength: 0.1, Denoising strength: 0.57, Clip skip: 2, ENSD: 31337, Mask blur: 4

Show results

  • Here are two pictures I drew for reference.
    Please add a picture description
    Please add a picture description

Guess you like

Origin blog.csdn.net/qq_20144897/article/details/130847438