Generating an image
Now that we have the Stable Diffusion model loaded up to the GPU, let’s generate an image. text2img_pipe
holds the pipeline object; all we need to provide is a prompt
string, using natural language to describe the image we want to generate, as shown in the following code:
# generate an image prompt ="high resolution, a photograph of an astronaut riding a horse" image = text2img_pipe( prompt = prompt ).images[0] image
Feel free to change the prompt to anything else that comes to your mind when you are reading this, for example, high resolution, a photograph of a cat running on the surface of Mars
or 4k, high quality image of a cat driving a plane
. It is amazing how Stable Diffusion can generate images according to a description in purely natural language.
If you run the preceding code without changing it, you may see an image like this showing up:
Figure 3.1: An image of an astronaut riding...