---
description: Discover the Ultralytics SAM and SAM 2 module for object segmentation. Learn about its components, such as image encoders and mask decoders, in this comprehensive guide.
keywords: Ultralytics, SAM Module, SAM 2 Module, object segmentation, image encoder, mask decoder, prompt encoder, AI, machine learning
---

# Reference for `ultralytics/models/sam/modules/sam.py`

!!! success "Improvements"

    This page is sourced from [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/sam/modules/sam.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/sam/modules/sam.py). Have an improvement or example to add? Open a [Pull Request](https://docs.ultralytics.com/help/contributing/) — thank you! 🙏

<br>

## ::: ultralytics.models.sam.modules.sam.SAMModel

<br><br><hr><br>

## ::: ultralytics.models.sam.modules.sam.SAM2Model

<br><br><hr><br>

## ::: ultralytics.models.sam.modules.sam.SAM3Model

<br><br>
