--- description: Explore the TwoWayTransformer module in Ultralytics, designed for simultaneous attention to image and query points. Ideal for object detection and segmentation tasks. keywords: Ultralytics, TwoWayTransformer, module, deep learning, transformer, object detection, image segmentation, attention mechanism, neural networks --- # Reference for `ultralytics/models/sam/modules/transformer.py` !!! success "Improvements" This page is sourced from [https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/sam/modules/transformer.py](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/models/sam/modules/transformer.py). Have an improvement or example to add? Open a [Pull Request](https://docs.ultralytics.com/help/contributing/) — thank you! 🙏
## ::: ultralytics.models.sam.modules.transformer.TwoWayTransformer



## ::: ultralytics.models.sam.modules.transformer.TwoWayAttentionBlock



## ::: ultralytics.models.sam.modules.transformer.Attention