論文閱讀 ICCV 2021 — Unifying Nonlocal Blocks for Neural Networks

該論文在 NL Block 的設計方法上提出新觀點,以 Spectral view 統合過去發展的不同變體,並提出 Spectral Nonlocal Block ( SNL ) ,在不同種的視覺任務上達到 SOTA 的水準。

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

--

論文連結:
《 Unifying Nonlocal Blocks for Neural Networks 》

作者:

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021.

GitHub Link

Introduction

在電腦視覺的相關任務中,不論是處理時間或空間的維度,捕捉 Long-range spatial-temporal dependencies 都是個關鍵的環節。

由於 Convolution operator 本身是處理 Local 的一種做法,這會導致 CNN 對 Long-range spatial-temporal dependencies 的建模能力受限。

為增加它在這方面的建模能力,過去的做法多是透過堆疊多層的 Convolution operators 來增加視野域,然而這會導致下列 2 個問題:

  1. 計算量、記憶體使用量提高,且容易導致 Over-fitting 。
  2. 堆疊多層的 Convolution operators 並不見得能有效增加視野域,相關說明可參考這篇論文

為解決這問題,過去曾有相關研究提出 Non-local Neural Networks 。簡單來說,是透過 Affinity matrix 紀錄各位置的關聯性,再將它當作 Attention map ,並以加權平均的算法來聚合特徵 。

但這種作法會紀錄到太大量的關聯性資訊,導致聚合過程有太多的雜訊存在 ( 例如,背景跟背景之間的關聯性其實不太重要 ) 。

近期的相關研究則開始聚焦在 Attention map 的合理性,例如:A²-NetCGNLCCNet 都各自用了不同方法改善了 Non-local block 的 Attention 機制,但在 Filter 的部份大多使用 1 × 1 Convolution ,所以仍缺乏捕捉 Long-range dependencies 的能力,如下圖的 A 部份:

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Figure 1.

為了克服這個限制,該論文希望在 Filter 的部份採用 Graph 的作法,也就是上圖的 B 部份 。輸入資訊會先依據特徵的相似性來建構全連接的 Graph,最終的輸出則透過具備學習能力的 Graph filter 來生成,在該論文以 Spectral view 來稱呼這作法。

此外,該論文還透過理論推導出過去作法的不足之處,並以 Graph 的本質來克服此問題。而新提出的 Non-local block 稱為「 Spectral Nonlocal ( SNL ) Block 」,除了有更好的理論基礎外,也具備更高精準度和整合上的彈性。

Contributions

  • 對於 Nonlocal-based block 的設計方法提出新的觀點,可更有彈性地捕捉 Long-range dependencies
  • 借助 Chebyshev approximation 對目前 5 種知名的 Non-local block 作法進行統整及詮釋
  • 善用 Graph 本質提出新穎的 Spectral Nonlocal ( SNL ) Block ,在不同視覺任務上具備其泛用性

Preliminary

Nonlocal Block

上圖的 A 部份主要是計算所有配對資訊的加權平均,可以下方公式表述:

X 是輸入特徵圖;i, j 是來表示其位置;f(·) 是帶有 Frobenius norm 的 Affinity kernel;g(·) 是個線性的嵌入算法。

當這種 NL Block 嵌入於神經網路時,會結合 Residual link 和一組做線性變換的權重 ( 以 W 表示 ):

Graph Fourier Transform & Graph Filter

若以 G 表示 Graph ,N 表示 G 的各節點,那任意的 Function ( or signal ) vector 則可表示成:

而 f(i) 則表示 G 的第 i 個節點的 Function value 。

再進一步根據 Graph Laplacian 的 Eigenvectors 來看,Fourier transformation 的過程可表述為:

其中的 λ 、U 是 Eigenvalues 和 Eigenvectors:

而 f Head of λ 則是對應 u_l 的 Spectral coefficient 。( u_l 有上標 * 則是指 U Transpose 的 Row vector )

而 Graph filter 會基於輸入資訊 ( x ) 的 Eigenvalues ( U ) 改變它的組成,改動的依據就是按照 λ 的 Frequency response ( g_θ )。

基於前述假設,若對 G 的 x 應用 Graph filter 則可表述成:

另外也可參照這篇論文表述成:

Approach

一個 Non-local operator 可以從 Spectral domain 來詮釋它,也可把它看成是在全連接的 Weighted graph 應用一組 Graph filters。

這個處理過可以大致分為以下 2 步驟:

  1. 生成全連接的 Graph,並對 Position pairs 的相似性進行建模
  2. 將輸入資訊的特徵轉換至 Graph domain,再透過 Graph filter 來學習

而該論文提出的框架則是對 Non-local operator 定義出 Spectral view ,並藉此統一 5 種現有的作法 ,再以此框架為基礎提出新穎的 Non-local block。

The Spectral View of Nonlocal-based blocks

為了定義這個 Spectral view ,首先延續前面公式並將原本的 W 分解成下標 s1 和 s2 的樣子:

其中的 A 是 Affinity matrix :

而 M 是由不同像素之間的相似性組成的:

這邊的 f(·) 是 Dot product

Affinity matrix 的 D 是個 Diagonal matrix ,紀錄著 M 上每個節點的 Degree

Z 則是透過線性變換將 X 的 Channel 進行壓縮的結果:

有下標 s1 和 s2 的 W 是兩個 Parameter-matrix,用來過濾具備鑑別度的特徵

基於前述公式,將下標 s1 的 W 泛化成一組 Graph filter:

就可以 Spectral view 來表述相同的公式:

而在 Spectral view 的 Non-local operator 是:

若假設 C_1 = C_s ,則可簡化成:

從這角度來看,Non-local operator 會先計算 Affinity matrix 之後,再透過 g_θ 學習 Graph spectral features 。該論文用這角度來詮釋其他相關作法,並整理出下表:( 詳細的推導過程請參考原文 )

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Table 1.

Designing Spectral Nonlocal Blocks

該論文定義出這個 Spectral view 也有助於設計新的 Non-local block:Spectral Nonlocal Block ( SNL ),和過去部份作法同樣基於 Chebyshev filter 。

現有作法不是使用 Random walk normalized ( NL, NS, CGNL, CC ) 就是 Non-normalized affinity matrix ( A² ),這些作法的對稱性質並無法保證 Affinity kernel 的表現 ,也不會將 Graph 轉換至 Spectral domain,並在計算 Graph Laplacian 要牽涉到大量、複雜的 Eigenvalues 。這些問題在全連接的 Graph model 上更是被進一步放大 。

此外,現有作法只有使用二次或一次逼近,也可能限制其表現的能力。

考量到前述的種種因素,該論文提出的 SNL 應用更完整的逼近方法:

其中有下標 s 的 F(A, Z) 就是 SNL Operator 。

主要的想法是將 Chebyshev filter 泛化成 Graph 的 Filter,其中的 A 是個 Symmetric affinity matrix ,用來確保 Real eigenvalue 的存在,可使神經網路的表現更穩定。

此外,在逼近的作法上採用更完整的一次 Chebyshev Approximation ,可以更精準地逼近出 Graph filter,使其學習的空間更自由。

SNL Operator 示意圖如下:

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Figure 2.

Experiments

該論文的實驗是採用 CIFAR-10/100 和 ImageNet 資料集,模型則是用 Pre-ResNet56 ( for Ablation study ) 和 ResNet50 ( for Main result )。其他細節可參考原文

Ablation Studies

這部份是針對轉換特徵時的 Channel 數做實驗,對應到前面公式就是 C_s 的數值,由於這部份是為了避免雜訊出現,所以作法上是對該維度進行壓縮:

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Table 2.

Non、Half、Quarter 就是壓縮的幅度,不管在哪種情況下 SNL 都是最優的。

接著是針對嵌入 SNL 的位置進行實驗:

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Table 3.

有關嵌入更多 Non-local block ( 3個 ) 的比較:

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Table 5.

Main Results

這部份的模型只有在 ResNet50 的 res4 後面嵌入單一個 SNL Block,並與其他方法比較。下表是在 CIFAR-10 / 100 資料集的結果:

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Table 4.

而在 ImageNet 的比較結果如下:

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Table 6.

成果大多都有比較好一些,但也要付出對應的運算成本。

在視覺化的部份,除了將特徵圖直接呈現 ( 下圖 A ) 外,還有針對配對關係進行處理 ( 下圖 B ,和橘色點有關的 Heat map 會有 ORN 的前綴,和粉紅色點有關的 Heat map 就是 PINK- 的前綴 ):

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Figure 3.

可以更直觀地看到 SNL 比過去作法更能找出合理的關聯性 。

另外還有關於行為辨識的實驗:

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Table 7.

以及語意分割的實驗:

Zhu, Lei, Qi, She, Duo, Li, Yanye, Lu, Xuejing, Kang, Jie, Hu, and Changhu, Wang. “Unifying Nonlocal Blocks for Neural Networks.” . In IEEE International Conference on Computer Vision (ICCV).2021. Table 8.

基本上都有做出更好的成果,證明該方法的泛用性 。

Conclusion

該論文在 Nonlocal-based block 的設計上提出一個新的觀點,並定義出 「 Spectral view 」的框架,鍊結了過去發展出的不同變體和 Graph signal processing 的關係。

在此框架之下,該論文以更好的理論基礎提出「 Spectral Nonlocal Block ( SNL ) 」,在不同種的視覺任務上,展現其強健性與泛用性 。

--

--

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

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