Get SAM Embedding
Encode an image once for fast masking
- sam_model
- image
- SAM_EMBEDDING
SAM - Meta's Segment Anything Model - is the thing that lets you point at an object in an image and get a clean mask around it, no manual lassoing. It's the backbone of a lot of masking and inpainting work in ComfyUI (Impact Pack's SAM integration is the version most people have met). This node is a lower-level piece of that machinery: it runs SAM's image encoder and hands you back the resulting embedding.
Why would you want the raw embedding instead of a finished mask? Because encoding the image is the expensive part, and it only has to happen once. Compute the embedding, and then generating masks from clicks, points, or boxes against it is cheap and fast. If you're building an interactive or repeated masking flow, separating "encode the image" from "make a mask" is the optimization that makes it snappy.
How it works
SAM has two halves: a heavy image encoder that turns the whole picture into a dense feature representation, and a light mask decoder that takes prompts (points/boxes) and spits out masks. This node runs only the first half. You give it a loaded SAM model and an image; it returns a SAM_EMBEDDING - the encoded picture, ready for the decoder step downstream. Encode once, mask many times.
The inputs and outputs
- sam_model (
AV_SAM_MODEL) - a SAM model loaded by the pack's SAM loader node. This is the checkpoint that does the encoding. - image (
IMAGE) - the picture to encode. - device_mode (optional) -
AUTO,Prefer GPU, orCPU. The encoder is the compute-heavy part, so GPU is faster; drop to CPU if you're tight on VRAM and don't mind the wait.
The single output is SAM_EMBEDDING. On its own it's not viewable - it's an intermediate. Wire it into SAM Embedding to Image to visualize what got encoded, or into a decoder/mask step to actually cut out an object.
Installing it
ComfyUI Manager: search comfyui-art-venture, install, restart. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/sipherxyz/comfyui-art-venture
then restart. You'll also need a SAM model file for the loader to point at - SAM checkpoints (ViT-B / ViT-L / ViT-H) come from Meta's release and go in your models folder. On comfy.icu the pack is pre-installed in the shared image.
Common issues
Like the rest of this pack, the node shows up red and "missing" if you open a workflow that uses it without the pack installed - art-venture is a common quiet dependency. Manager's "Install Missing Custom Nodes" resolves it.
The other snag is the SAM model itself. If the loader has nothing to load, or you picked a model your VRAM can't hold, you'll get errors here at encode time - the bigger ViT-H checkpoint is accurate but heavy, ViT-B is the light option. And remember this node produces an embedding, not a mask; if you were expecting a cut-out and got something you can't preview, you're one node too early in the pipeline. Feed it forward.
Honestly, if all you want is "detect a person and mask them," Impact Pack's higher-level SAM nodes are the friendlier route. Reach for this pair when you specifically want the embedding as a reusable, cache-once building block.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| sam_model | AV_SAM_MODEL | — | |
| image | IMAGE | — | |
| device_modeopt | COMBO | 3 options: AUTO, Prefer GPU, CPU |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| SAM_EMBEDDING | SAM_EMBEDDING | — |