Docs
gpu
AI Painting
AI Drawing jupyter Practice

AI Painting Stable Diffusion Practice

1. Create a GPU Cloud Host

The creation process refers to Creating the First Cloud Host.
When creating a GPU cloud host, please choose the image “AI painting stable diffusion platform” for the image. The operation path is: Image market—>AI painting stable diffusion platform. This image provides a convenient installation of stable diffusion and comes with the built-in environment: CentOS 7.8.
Recommended types and configurations:
GPU Cloud Host T4/T4S Minimum configuration: 8 cores 32G single GPU
GPU Cloud Host V100S Minimum configuration: 10 cores 32G single GPU
GPU Cloud Host P40 Minimum configuration: 8 cores 32G single GPU

Please choose 32GB or above memory, otherwise it may trigger OOM when loading the model.
Bind the EIP and allow TCP 8888 port in the external network firewall.

2. Using Stable Diffusion

2.1 Method One: Use Jupyter Notebook to Create a New LDM Environment (Recommended)

Access Jupyter by your external network IP address: http://EIP:8888 Enter the token (You can check the configuration of c.NotebookApp.token in /root/.jupyter/jupyter_notebook_config.py, and you can modify it as you wish.)

Create a new LDM.

If you use English version description, please refer to the following example:

After adding the following example code, please run (Use “A thriving view alongside Pearl of the Orient in Shanghai, by Van Gogh, oil painting trending on artstation HQ” as an example)

from torch import autocast
from diffusers import StableDiffusionPipeline
from IPython.display import Image
 
width = 512
height = 512
 
pipe = StableDiffusionPipeline.from_pretrained(
    "/root/demo/stable-diffusion-v1-4").to("cuda")
 
prompt = "A thriving view alongside Pearl of the Orient in Shanghai , by Van Gogh, oil painting trending on artstation HQ"
with autocast("cuda"):
    image = pipe(prompt, height, width)["sample"][0] 
     
image.save("Van_Gogh_Style_Shanghai.png")
 
# Show the image in web
Image(filename = 'Van_Gogh_Style_Shanghai.png', width=width, height=height)

You can view the generated picture immediately.

If you use Chinese version description, please refer to the following example:

After adding the following example code, please run (Use “The vast desert smoke straight, the long river sunset round, oil painting” as an example)

from diffusers import StableDiffusionPipeline
from IPython.display import Image

width = 512
height = 512

pipe = StableDiffusionPipeline.from_pretrained("IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1").to("cuda")

prompt = 'The vast desert smoke straight, the long river sunset round, oil painting'
image = pipe(prompt, guidance_scale=7.5).images[0]  
image.save("Oil_painting.png")

# Show the image in web
Image(filename = 'Oil_painting.png', width=width, height=height) 

You can view the generated picture immediately.

  1. Select the code partition, click [Run], if you see “In[*]”, that means the code is running, just wait for the output result;
  2. If you need to adjust the canvas size, make sure that both width and height are multiples of 8.

If you want to try quickly, you can directly use SD_Demos.ipynb under the demo/ path, which includes English and Chinese model

2.2 Method Two: Use Sample Script of Stable Diffusion

2.2.1 Switch Conda Environment

conda activate ldm

2.2.2 Run the Sample Script

Run the script, input your expected description of the painting, and you will get the picture (Take “A valley full of flowers, by Van Gogh, oil painting trending on artstation HQ” as an example), the generated picture will be found in the directory /root/stable-diffusion/outputs/txt2img-samples/.

cd stable-diffusion
python scripts/txt2img.py --prompt "A valley full of flowers , by Van Gogh, oil painting trending on artstation HQ"

2.2.3 Check the Picture via Jupyter Page

Access Jupyter by your external network IP address: http://EIP:8888

Enter the token (You can check the configuration of c.NotebookApp.token in /root/.jupyter/jupyter_notebook_config.py, and you can modify it as you wish.)

Click to preview the picture according to the navigation.