liveBook · Manning

Prompt

As explained in Deep Learning with PyTorch, Second Edition

User-provided guidance such as points, boxes, or masks that steers the segmentation model toward a desired object or region.

A prompt is user-provided guidance that tells a model what to produce or which object or region to select. In image segmentation, prompts can be points, boxes, or masks; in inpainting, a text prompt describes the intended edit. section 15.3.1 section 2.2.1

Prompts clarify different parts of an image task:

  • A text prompt says what the result should contain, such as turning a horse into a zebra. section 2.2.1
  • A point, box, or mask identifies the object or region that a segmentation model should select. section 15.3.1
  • In inpainting, the prompt describes the change, while the image supplies the starting scene and the mask limits where changes occur. section 2.2.1

Replacing a horse with a zebra

An inpainting pipeline can receive the prompt "a zebra replacing the original horse, same pose, same lighting, background unchanged" together with a horse image and mask. The prompt specifies the replacement; the mask confines the edit to the selected region. section 2.2.2

# In[5]:
mask_img = Image.open("../data/p1ch2/horse_mask.jpg")

prompt = ("a zebra replacing the original horse, same pose, same lighting, background unchanged")
negative = "distorted background, blurry, text, watermark"   #1

out = pipe(
    prompt=prompt,
    image=img,
    mask_image=mask_img,
    negative_prompt=negative,
    guidance_scale=7.5,
    strength=0.8,
    generator=torch.Generator(device).manual_seed(42)
)

Inspect a complete prompt passed alongside an input image, mask, negative prompt, and generation settings. section 2.2.2

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Distinguishes prompt roles and demonstrates invocation, while deferring model internals and prompt-generation details.
Examples
Uses a horse-to-zebra edit and segmentation inputs consisting of points, boxes, or masks.
What it assumes
Assumes basic familiarity with images and masks while explaining the separate roles of prompts, input images, and masks.
What you can do after
Apply prompts through an inpainting pipeline or use them to guide segmentation masks without task-specific fine-tuning.
How it connects
Connects text prompts with image-to-image generation, inpainting, masks, and zero-shot segmentation.

Also explained in

Compare how 50 books explain prompt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.