เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การแก้ไขภาพแบบกำหนดเอง

การสร้างภาพด้วย AI นั้นน่าทึ่งอยู่แล้ว แต่บางโมเดลยังรองรับการแก้ไขภาพแบบกำหนดเอง ซึ่งเป็นรูปแบบ multi-modal ที่รับทั้ง text prompt และภาพต้นฉบับเป็น input ลองแก้ไขภาพเหมือนตนเองอันโด่งดังของ Van Gogh ให้กลายเป็นตัวการ์ตูน Snoopy โดยใช้ StableDiffusionControlNetPipeline:

Famous Van Gogh painting

หมายเหตุ: การ Inference บน diffusion model อาจใช้เวลานาน เราจึงโหลดภาพที่สร้างไว้ล่วงหน้าให้แล้ว การใส่ prompt ต่างกันจะไม่สร้างภาพใหม่

ภาพที่ผ่านฟิลเตอร์ Canny ถูกสร้างไว้ให้แล้ว (canny_image) คลาส StableDiffusionControlNetPipeline และ ControlNetModel ถูก import จากไลบรารี diffusers มาแล้ว และ generator list (generator) ก็ถูกสร้างไว้ให้แล้วเช่นกัน

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

โมเดล Multi-Modal ด้วย Hugging Face

ดูคอร์ส

คำแนะนำการฝึกหัด

  • โหลด ControlNetModel จาก checkpoint lllyasviel/sd-controlnet-canny
  • โหลด StableDiffusionControlNetPipeline จาก checkpoint runwayml/stable-diffusion-v1-5 โดยส่ง controlnet ที่เตรียมไว้
  • รัน pipeline โดยใช้ prompt, canny_image และ negative_prompt กับ generator ที่เตรียมไว้

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

## NOTE: no imports are required for this exercise
# Load a ControlNetModel from the pretrained checkpoint
controlnet = ____("____", torch_dtype=torch.float16)

# Load a pretrained StableDiffusionControlNetPipeline using the ControlNetModel
pipe = ____(
    "____", controlnet=____, torch_dtype=torch.float16
)
pipe = pipe.to("cuda")

prompt = ["Snoopy, best quality, extremely detailed"]

# Run the pipeline
output = pipe(
    ____,
    ____,
    negative_prompt=["monochrome, lowres, bad anatomy, worst quality, low quality"],
    generator=____,
    num_inference_steps=20,
)

plt.imshow(output.images[0])
plt.show()
แก้ไขและรันโค้ด