Sub topic 1
What Promptable Segmentation Means
Prerequisites
This chapter assumes that you know basic Python and NumPy, and that you can distinguish image classification, object detection, and image segmentation. You should also understand that a pretrained model uses learned parameters loaded from a checkpoint. Familiarity with PyTorch tensors and the basic idea of Vision Transformers is helpful.
The task
Image segmentation assigns a label to pixels. In ordinary semantic segmentation, the model might label every pixel as car, road, or sky. In instance segmentation, it also separates different objects of the same class, such as two cars.
Promptable segmentation uses a different input. Instead of asking the model to find every object from a fixed list of classes, you give it a prompt that identifies the region or object you want. The output is a mask, which is a grid of Boolean values or probabilities with the same spatial meaning as the image. A foreground value marks pixels that belong to the selected region.
A prompt can be a foreground point, a background point, a rectangle, or an earlier mask. For example, a point on a person tells the model, “segment the object associated with this location.” A rectangle says, “find the object or region inside this area.” Background points can rule out nearby objects.
The model does not need a separate output class for every object category. It uses visual evidence, such as edges, textures, and shapes, together with the prompt. This makes the task useful when the object categories are unknown or change between applications.
Why this enables zero-shot transfer
Zero-shot transfer means applying a model to a task or object type that was not specified during application-specific training. SAM, the Segment Anything Model, was trained with a large and varied collection of images and masks. During use, you do not normally fine-tune it for “this particular kind of tool” or “this particular person.” You provide a prompt, and the model predicts a mask.
This works because the model learns general visual concepts about boundaries and regions rather than only memorizing a closed class list. A prompt supplies the instance-specific information that a fixed classifier would otherwise need to learn from labeled examples.
Zero-shot does not mean that the model has no training or that it understands every object perfectly. It means that the user can transfer the pretrained model to a new image and often a new object category without adding task-specific training. Image quality, object size, unusual shapes, and ambiguous boundaries still affect the result.
A working model
SAM can be understood as a contract between three things:
- The image provides visual evidence.
- The prompt identifies the intended region.
- The predicted mask describes the selected pixels.
The same image can produce different masks when the prompt changes. A point on a person and a point on a bicycle may select different objects. A box around both objects may be ambiguous, because several valid interpretations are possible.
Promptable versus fixed-task segmentation
A fixed-task segmentation model usually has a predefined label set and produces masks for those labels. Its interface might always ask for “all road pixels” or “all tumor pixels.” This can be efficient when the domain and labels are stable, but changing the task often requires new training data or a new model.
A promptable model has a more flexible interface. The application can let a person click an object, draw a box, or provide a previous mask. The model then segments the prompted region. This makes it suitable for annotation tools, image editing, scientific inspection, and data preparation.
The flexibility also shifts some responsibility to the user or calling program. A poor prompt can select the wrong object. The application must inspect the returned mask, handle uncertainty, and sometimes ask for corrective prompts. Promptable segmentation is therefore best viewed as an interactive prediction process rather than a guaranteed one-click solution.
Exercise
Exercise
Why can a point prompt help SAM segment an object category that was not part of an application's custom training set?
Show answer
The point supplies instance-specific location information, while the pretrained model supplies general visual knowledge about regions and boundaries. No new class-specific training is required for that image.