# EfficientFormer ViT:https://arxiv.org/abs/2010.11929 V1:https://arxiv.org/abs/2206.01191 V2:https://arxiv.org/abs/2212.08059 目的:Transformer 因為 Attention 機制和大量的參數,在 ViT 方面還沒有辦法做到像 MobileNet 即時辨識,在 Efficient Former 之前有許多研究結合 MobileNet 的 block 和 transformer 的實驗,但運算速度還是沒有很快。這篇 paper 提出一個可以即時運算的純 Transformer。 ## ViT  將輸入的圖片切割成數個 Patches 假設原輸入圖片大小為 $H * W$,Patch 大小為 P 就會切出 $(H*W) / (P*P)$ 個 Patch 將這些 Patch 展平成向量後經過 Linear 映射  再加上 Position Embedding 一起送入 Transformer Encoder 另外,還會在 Linear projection 過後的序列開頭加上一個 learnable class token 一開始用隨機數初始化,在訓練過程中被更新,用來學習每個 patch 和目標的關聯性。 Encoder 結構基本與原文字處理 Transformer 相同 經過 Encoder 和全連接層 MLP Head (two layers with a GELU) 後輸出 ## EfficientFormer  從實驗中觀察到以下幾件事: * Patch embedding is often implemented with a non-overlapping convolution layer that has large kernel size and stride,這可能造成在移動裝置上的速度瓶頸 * Multi head self attention (MHSA) 不一定是速度瓶頸,頻繁的 Reshaping 才是造成效率低落的元兇。對於 token mixer(pooling 或 MHSA)來說,一致的 dimension 很重要(要避免一直 reshape,pooling 和 MHSA 就不會有太大速度差異) * Conv-BN 會比 LN 或 GN 來的有效率,且造成的準確率下降是可接受的。所以在 $MB^{4D}$ 都採用 Conv-BN;而 3D features 的地方跟原 ViT 的 MHSA 設計一樣都用 LN,達到更好的效果。 * 非線性的延遲取決於硬體及編譯器(在 iPhone 12 上測試,GeLU 與 ReLU 速度接近)。 In this work, we employ GeLU activations 4 stages:  ## EfficientFormerV2  加入局部資訊可以提高 ViT 準確率,且在 Feed Forward Network (FFN) 加入局部資訊也可以帶來好處。原本 V1 是用 Pooling 當作 Local token mixer (residual-connected),V2 刪掉這個 Pooling 層,改成depth-wise convolutions (DWCONV),並將 DWCONV 移入 FFN。  另外,重新進行搜索,發現 wider and narrower network 可以有更高準確率、更少參數、更小的延遲。 在 MHSA 中加入 Talking Head 機制 -> 在 Attention Heads 之間加入 Fully Connected 也在 Matrix V 中加入局部資訊 -> DWCONV 在高解析度引入 MHSA 可以提高準確度,但非常吃效能,這裡的解決方法是 Stride Attention:把 Q、K、V 全部 Downsample 成 $\frac{1}{32}$ 來做運算,再把 output 插值回原本解析度並餵給下一層。 **Dual-Path Attention Downsampling:** 除了 strided conv 和 pooling 兩種 downsampling 方式,也有人提出 attention downsampling,更好的保留 global 上下文資訊。做法是將 query 的 token 數減半,以達成 attention 輸出的 downsample。作者結合 pooling 和 DWCONV 作為 local downsampling,同時 residual-connected stride conv 以達到 local-global downsampling。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up