> For the complete documentation index, see [llms.txt](https://xa9ax.gitbook.io/echo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xa9ax.gitbook.io/echo/echoai.attentioncv/cv/pytorch.md).

# PyTorch

## Triplet Attention

```python
echoAI.Attention.cv.t_attn.TripletAttention(no_spatial = False, kernel_size = 7)
```

![Triplet Attention](/files/-MMY5lusdjxnOzPcAVS-)

#### Parameters: <a href="#triplet-parameters" id="triplet-parameters"></a>

* **no\_spatial** - switches on the spatial attention branch in Triplet Attention. Default: `False`
* **kernel\_size** - window size of the convolution filters in Triplet Attention. Default: 7

#### Shape: <a href="#triplet-shape" id="triplet-shape"></a>

* Input:$$(\mathbf{N}, \mathbf{C}, \mathbf{H}, \mathbf{W})$$4 dimensional feature map tensor.
* Output:$$(\mathbf{N}, \mathbf{C}, \mathbf{H}, \mathbf{W})$$,same shape as input

#### Reference: <a href="#triplet-reference" id="triplet-reference"></a>

[Rotate to Attend: Convolutional Triplet Attention Module](https://arxiv.org/abs/2010.03045)

## Squeeze Excite Attention

```python
echoAI.Attention.cv.t_attn.SE(gate_channels, reduction_ratio = 16)
```

![Squeeze Excite Attention](/files/-MMY6qNds-hRqAbaQAwu)

#### Parameters: <a href="#se-parameters" id="se-parameters"></a>

* **gate\_channels** - number of channels in the input tensor. Datatype: `Integer`
* **reduction\_ratio** - squeeze bottleneck factor of the MLP in Squeeze Excite Attention. Default: 16

#### Shape: <a href="#se-shape" id="se-shape"></a>

* Input:$$(\mathbf{N}, \mathbf{C}, \mathbf{H}, \mathbf{W})$$4 dimensional feature map tensor.
* Output:$$(\mathbf{N}, \mathbf{C}, \mathbf{H}, \mathbf{W})$$,same shape as input

#### Reference: <a href="#se-reference" id="se-reference"></a>

[Squeeze-and-Excitation Networks](https://arxiv.org/abs/1709.01507)

## Convolutional Block Attention Module&#x20;

```python
echoAI.Attention.cv.t_attn.CBAM(gate_channels, kernel_size = 3, reduction_ratio = 16, pool_types = ['avg', 'max'], no_spatial = False, bam = False, num_layers = 1, bn = False, dilation_conv_num = 2, dilation_val = 4)
```

&#x20;**Supports both Convolutional Block Attention Module (CBAM) and Bottleneck Attention Module (CBAM)**

![](/files/-MMY962A28mi_E7RleEs)

![Convolutional Block Attention Module and Bottleneck Attention Module](/files/-MMY9Rh54uUZn9GSLKMz)

#### Parameters: <a href="#se-parameters" id="se-parameters"></a>

* **gate\_channels** - number of channels in the input tensor. Datatype: `Integer`
* **kernel\_size** - window size of the convolution filters in CBAM/ BAM. Default: 3
* **reduction\_ratio** - width factor of the MLP in CBAM/BAM. Default: 16
* **pool\_types** - `list`of global pooling operators for channel attention gate in CBAM/BAM. Default: `['avg', 'max']`. Note: This is the default for CBAM, which expects two operators, however, if BAM is switched on, pass `['avg']`. Available options: `avg`, `lp`, `max`
* **no\_spatial** - switches off the spatial attention gate in CBAM. Default: `False`
* **bam** - initializes BAM. Default: `False`
* **num\_layers** - controls the number of hidden layers in the MLP of channel attention gate in CBAM/BAM. Default: 1
* **bn** - adds a Batch Normalization layer in the MLP of the channel attention gate in CBAM/BAM. Default: `False`. Pass True when **bam** is `True`.
* **dilation\_conv\_num** - number of dilated channel preserving convolution layers in the spatial attention gate in BAM. Default: 2
* **dilation\_val** - dilation factor for the convolution layers in the spatial attention gate in BAM. Default: 4

{% hint style="info" %}
Note: By default, CBAM is initialized.
{% endhint %}

#### Shape: <a href="#cbam-shape" id="cbam-shape"></a>

* Input:$$(\mathbf{N}, \mathbf{C}, \mathbf{H}, \mathbf{W})$$4 dimensional feature map tensor.
* Output:$$(\mathbf{N}, \mathbf{C}, \mathbf{H}, \mathbf{W})$$,same shape as input

#### References: <a href="#cbam-references" id="cbam-references"></a>

[CBAM: Convolutional Block Attention Module](https://arxiv.org/abs/1807.06521)

[BAM: Bottleneck Attention Module](https://arxiv.org/abs/1807.06514)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://xa9ax.gitbook.io/echo/echoai.attentioncv/cv/pytorch.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
