論文閱讀 WACV 2021 — Rotate to Attend: Convolutional Triplet Attention Module

該論文提出 Triplet attention ,是一種新穎的 Attention layer ,可跨維度地捕捉重要特徵,且無須借助任何 Bottleneck 結構就做出非常輕量的設計,在幾個常見的資料集上都有不錯的成果。

Ken Huang
人工智慧,倒底有多智慧?
15 min readSep 22, 2021

--

論文連結:
《 Rotate to Attend: Convolutional Triplet Attention Module 》

作者:

Misra, D., Nalamada, T., Arasanipalai, A., & Hou, Q. (2021). Rotate to Attend: Convolutional Triplet Attention Module. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) (pp. 3139–3148).

GitHub Link

Introduction

這些年來,加深 CNN 架構的作法已在許多視覺任務上展示其有效性。近年更有些研究提出 Channel / Spatial attention 的作法,並更進一步改善神經網路的效能。

這些 Attention 機制可透過額外的權重對 Channel 或 Spatial 維度建立相依性,並改善神經網路對特徵進行重現的能力。更直覺一點來說,這些額外的權重是要讓模型學會去專注在特定地方。

而該論文的目標是希望探討一個更有效率的 Attention 機制,為了讓 Attention weights 可提供更豐富的特徵重現,該論文將研究方向著重於捕捉 「 Cross-dimension interaction 」

基於對 CBAM、SENet 的觀察該論文提出「 Triplet attention 」,這方法包含 3 個 Branch,而每個 Branch 皆負責捕捉輸入特徵在 Spatial 和 Channel 維度之間的關聯性。

若將輸入特徵的維度以 ( C × H × W ) 表示,那每個 Branch 各自負責捕捉的就是 C、H 之間 & C、W 之間 & H、W 之間 的特徵 。

Misra, D., Nalamada, T., Arasanipalai, A., & Hou, Q. (2021). Rotate to Attend: Convolutional Triplet Attention Module. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) (pp. 3139–3148). Figure 1.

2 Advantages

與過往的 Channel attention 機制相比,該論文的作法有以下 2 個優勢:

  1. 以更少的計算量捕捉更豐富的特徵
  2. 不像過往作法採用降維的設計,消除 Channels 和 Weights 之間的間接對應關係

後續實驗證明,這方法是非常有效的,並輔以 Grad-CAM / Grad-CAM++ 的可視化結果進行驗證,相關實驗成果就留在後續章節呈現。

Related Work

人類在接收資訊時,會選擇性地專注在特定區塊,並忽略剩下的部份。這機制有助於完善資訊的涵構,而進幾年有許多研究嘗試在神經網路上模仿這種機制,並稱之為 「 Attention 」。

在眾多相關研究中,以下簡介幾個與該論文較相關的作法:

  • Squeeze-and-Excitation Networks
    為改善過去相關作法計算量龐大的缺點,SENet 使用 Global Avg Pooling 結合 1 × 1 Convolution,讓模型對每個 Channel 學出一個 Weight 來作到 Channel-wise attention 。
Misra, D., Nalamada, T., Arasanipalai, A., & Hou, Q. (2021). Rotate to Attend: Convolutional Triplet Attention Module. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) (pp. 3139–3148). Figure 2 (a).
  • Convolutional Block Attention Module
    延續著 SENet 的思維,在 Channel 的特徵加入 Global Max Pooling 所得到的 Spatial 特徵,又再進一步改善其成效。
Misra, D., Nalamada, T., Arasanipalai, A., & Hou, Q. (2021). Rotate to Attend: Convolutional Triplet Attention Module. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) (pp. 3139–3148). Figure 2 (b).
  • Global-Context Networks
    將 Non-local block 結合 SE Block,主要是透過一系列複雜的維度變換結合 1 × 1 Convolution 來聚合空間特徵,再做 Channel-wise attention 。
Misra, D., Nalamada, T., Arasanipalai, A., & Hou, Q. (2021). Rotate to Attend: Convolutional Triplet Attention Module. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) (pp. 3139–3148). Figure 2 (c).

然而過去的相關作法都沒有能力去捕捉 Cross-dimension interaction ,並且做了一些不必要的降維操作 。

Proposed Method

Triplet Attention Overview

上圖是 Triplet attention 的示意圖,圖中的不同 Branch 會以平行運算的方式捕捉 Cross-dimension interaction,最終以相加取平均的邏輯聚合資訊。

Cross-Dimension Interaction

傳統作法會對每個 Channel 計算單一個值當作 Weight ,並以它對每張特徵圖做 Scaling,是個極度輕量又有效的方法。

通常為了計算這個單一的 Weight ,會先對 Spatial 的維度做 Global average pooling,這步驟會使它喪失空間上的資訊,所以導致計算 Attention 的過程會喪失 Channel 和 Spatial 維度之間的關聯性。

過去的 CBAM 雖然有額外以 Spatial attention 模組試圖補足空間上的 Attention,但缺點是 Channel attention 和 Spatial attention 仍是獨立處理的,而它們之間的關聯性也就不得而知。

受到 Spatial attention 的啟發,該論文提出「 Cross dimension interaction 」的概念,並以這概念設計 Triplet attention ,用來捕捉 ( C, H ) 、( C, W )、( H, W ) 等不同維度之間的關聯性,藉此解決前述問題。

Z-pool

從上方的示意圖會發現,每個 Branch 都會有一個 Z-pool layer ,它是用來減少第 0 維度的操作,作法是對該維度做 Max pooling 和 Average pooling 之後直接串接起來:

0d 就是指第 0 個維度

這操作會讓原本是 C × H × W 的 Tensor 變成是 2 × H × W ,可讓特徵圖減少深度,計算上也就更輕量,但同時保有豐富的特徵重現。

Triplet Attention

在 Triplet attention 的計算過程中,統一將輸入特徵以 χ 表示 ( Shape 為 C × H × W ) ,並就 3 個不同 Branch 分別說明:

  • 第 1 個 Branch
    會先將 χ 依著 H 軸做逆時針旋轉 90◦ ,使 Shape 變成 W × H × C 。
    再經過 Z-pool layer 後,變成 2 × H × C 。
    接著是用標準的 k × k Convolution 和 Batch normalization 進行特徵抽取,並將維度再壓縮成 1 × H × C 之後,以 Sigmoid activation function ( σ ) 生成 Attention weight。
    最後再將這組權重依照 H 軸做順時針旋轉 90◦,讓 Shape 等同於一開始的輸入。
  • 第 2 個 Branch
    這個 Branch 作法類似於第 1 個 Branch ,只是這邊以 W 維度作為旋轉軸,所以 Shape 就會是 H × C × W。
    同樣經過 Z-pool layer 後,變成 2 × C × W。
    經過 Convolution 、Batch normalization 和 Sigmoid 之後變成 1 × C × W 的 Attention weight。
    最後依照相同旋轉軸 ( W ) 做反向的旋轉,變回一開始輸入的 Shape 。
  • 第 3 個 Branch
    最後一個 Branch 就更單純了,完全不做任何選轉的操作,所以 Shape 就是一開始的 C × H × W。
    一樣經過 Z-pool layer 後,變成 2 × H × W。
    再傳給相同配置的 Convolution 、Batch normalization 和 Sigmoid 之後會得到 1 × C × W 的 Attention weight,在應用於原本的 χ 。

而這 3 個 Branch 的輸出最終會用取平均的算法做資訊的聚合:

χ head 是經過旋轉的輸入資訊;再加上標 * 的 χ 是經過 Z-pool layer 的輸出;ψ 則是二維的 Convolution 操作;σ 是 Activation function 。

若將 3 組 Cross-dimensional attention weights 以 ω 表示,則上式可簡化成:

Complexity Analysis

針對相關作法,該論文也做了參數量的比較分析:

Misra, D., Nalamada, T., Arasanipalai, A., & Hou, Q. (2021). Rotate to Attend: Convolutional Triplet Attention Module. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) (pp. 3139–3148). Table 1.

上表的 C 就是 Channel 的數量,r 則是 Bottleneck 的 Reduction ratio,k 則是 2D convolution 的 Kernel size 。

而比較的方法是在 ResNet-50 的每個 Block 加入 Attention layer,r 設定為 16 , k 則依據不同方法有些差異:

  • CBAM 、Triplet attention:7
  • BAM 、GC 、SE:3

其中 BAM 的 Overhead 較低是因為根據原論文 Default 設定,它在整個架構只用了 3 次 。

Experiments

該論文的實驗做在 ImageNet 、PASCAL VOC 和 MS COCO 等知名的資料集,並採用 ResNet-50 、 MobileNetV2 等常見的模型架構。

ImageNet

在 ResNet 模型的改法是在每個 Bottleneck block 最後加入 Triplet attention layer,再根據先前相關研究的訓練配置來訓練模型。相關結果如下:

Misra, D., Nalamada, T., Arasanipalai, A., & Hou, Q. (2021). Rotate to Attend: Convolutional Triplet Attention Module. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) (pp. 3139–3148). Table 2.

整體來看,大多數的情況都可以在不太增加參數量的狀態,提昇其準確度 。

PASCAL VOC

針對 PASCAL VOC 資料集則是驗證該方法在物件偵測任務上的成效:

Misra, D., Nalamada, T., Arasanipalai, A., & Hou, Q. (2021). Rotate to Attend: Convolutional Triplet Attention Module. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) (pp. 3139–3148). Table 4.

結果也是有改善準確度 。

MS COCO

在 MS COCO 資料集則是驗證了更多種的 Detector:

部份結果和前兩個實驗類似,有些時候是 CBAM 表現得比較好,但參數量也相對高。

Ablation Study on Branches

這部份是為了驗證 Triplet attention 的不同 Branch 都是有幫助的:

Misra, D., Nalamada, T., Arasanipalai, A., & Hou, Q. (2021). Rotate to Attend: Convolutional Triplet Attention Module. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) (pp. 3139–3148). Table 5.

上表中會看到 Channel off / Spatial off 的字眼,表示分別的是第 1 & 2 個 Branch 和第 3 個 Branch 被關掉的情況。而 Full 就是完整的 Triplet attention ,也是成果最好的狀態。

Grad-CAM Visualization

為了驗證 Triplet attention 學到的是有意義的特徵,該論文有使用 Grad-CAM / Grad-CAM++ 來做可視化:

Misra, D., Nalamada, T., Arasanipalai, A., & Hou, Q. (2021). Rotate to Attend: Convolutional Triplet Attention Module. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) (pp. 3139–3148). Figure 4.

除了更能關注在相關的特徵外,甚至在某些原本判斷錯誤的個案中,加入 CBAM 或 Triplet attention 之後可以判斷正確,而 Triplet attention 可以讓模型更確定它推論的結果,算是證明了該方法確實能讓模型學到有意義的特徵。

Conclusion

該論文提出了一種新穎的 Attention layer ,稱為「 Triplet attention 」。這種 Attention 作法可以跨維度地捕捉重要的特徵,且無須藉由任何 Bottleneck 架構就能作到非常輕量,在幾個常見的資料集上都有不錯的成果。

--

--

Ken Huang
人工智慧,倒底有多智慧?

在網路上自學的過程中,體會到開放式資源的美好,希望藉由撰寫文章記錄研究所的學習過程,同時作為回饋網路世界的一種方式。Email : kenhuang2019iii@gmail.com ,如果有任何問題都歡迎與我聯繫。