0
0
Prompt Engineering / GenAIml~10 mins

Stable Diffusion overview in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the main library used for Stable Diffusion.

Prompt Engineering / GenAI
import [1]
Drag options to blanks, or click blank then click option'
Atorch
Btensorflow
Cnumpy
Dpandas
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing tensorflow which is another deep learning library but not the main one used here.
Choosing numpy or pandas which are not for deep learning.
2fill in blank
medium

Complete the code to load a pre-trained Stable Diffusion model using the diffusers library.

Prompt Engineering / GenAI
from diffusers import StableDiffusionPipeline
pipeline = StableDiffusionPipeline.from_pretrained([1])
Drag options to blanks, or click blank then click option'
A'gpt2'
B'bert-base-uncased'
C'resnet50'
D'stable-diffusion-v1-4'
Attempts:
3 left
💡 Hint
Common Mistakes
Using model names for other AI models like GPT or BERT.
Using image classification model names like resnet50.
3fill in blank
hard

Fix the error in the code to generate an image from a text prompt using the pipeline.

Prompt Engineering / GenAI
image = pipeline([1]="a beautiful sunset over mountains").images[0]
Drag options to blanks, or click blank then click option'
Aprompt
Bdescription
Cinput
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' or 'input' which are not valid parameter names here.
Using 'description' which is not recognized by the pipeline.
4fill in blank
hard

Fill both blanks to convert the generated image to a numpy array and display its shape.

Prompt Engineering / GenAI
import numpy as np
image_array = np.[1](image)
print(image_array.[2])
Drag options to blanks, or click blank then click option'
Aarray
Bshape
Csize
Dtolist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'size' which gives total elements, not shape.
Using 'tolist' which converts array to list, not what is asked.
5fill in blank
hard

Fill all three blanks to save the generated image to a file named 'output.png'.

Prompt Engineering / GenAI
from PIL import Image
img = Image.[1](image_array)
img.[2]('output.png', [3]='PNG')
Drag options to blanks, or click blank then click option'
Afromarray
Bsave
Cformat
Dopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'open' instead of 'fromarray' to create the image.
Not specifying the format or using wrong method to save.