or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
[Transformer_CV] Masked Autoencoders(MAE)論文筆記
tags:
Literature Reading
Vision Transformer
Paper
AI / ML領域相關學習筆記入口頁面
論文概覽
Masked Autoencoders Are Scalable Vision Learners
Encoder架構為Vision Transformer(ViT)
原始論文:An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
在NLP領域中,基於掩蔽自編碼(Masked Autoencoder)的自監督預訓練取得巨大的成功(BERT),而掩蔽自編碼器是一種更通用的去噪自編碼器(Denoised Autoencoder),也適用於計算機視覺,盡管如此,視覺自編碼方法的發展為何還是落後於 NLP?
本篇論文從以下幾點回答:
1、CV 和 NLP 主流架構不同:
2、語言和圖片 (視頻) 的信息密度不同:
3、 Decoder部分在 CV 和 NLP 中充當的角色不同:
為了克服這種差异並鼓勵學習有用的特征,論文中展示了:一個簡單的策略在計算機視覺中也能非常有效:掩蔽很大一部分隨機 patch。這種策略在很大程度上减少了冗餘,並創造了一個具有挑戰性的自監督任務,該任務需要超越低級圖像統計的整體理解。
模型架構
參考資料:
學習資源
核心程式碼筆記
初始化與整體前向傳播流程
loss
,pred
,mask
model.unpatchify(pred)
code
MAE的功能函式
將圖像區塊化 & 去區塊化
每個一維的序列長度: 16 x 16 x 3 = 768
則有 (224 x 224) / (16 x 16) = 14 x 14 = 196個patch
code
隨機遮蔽圖像
random_masking()
將圖像轉換成L(patch number)個1為的序列後,隨機抽樣決定那些圖塊(1d patch)要被遮蔽
input:
output: return
x_masked
,mask
,ids_restore
x_masked
mask
L是patch數量 * 被遮蔽的比例torch.gather(mask, dim=1, index=ids_restore)
根據ids_restore
指標位置對mask重新取值/排序ids_restore
ids_shuffle
與ids_restore
取得的index值其實是一樣的沒被遮蔽的圖塊(函式中的x_masked)在def forward_encoder()中,會加上cls token送入Transformer blocks中訓練
code
編碼器(encoder)
Encoder(ViT)內的Embedding
類別token
cls_tokens
位置編碼
pos_embed
shape : (batch, num_patches+1, embed_dim)
pos_embed.shape[-1] = embed_dim = 1024code
初始化建立編碼器(encoder)
位置編碼中的
self.pos_embed
中第二維度的num_patches + 1, 這個1是ViT架構中的類別編碼,加在最前面code MAE encoder
編碼器前向傳播流程
流程:
x = self.patch_embed(x)
每個一維圖塊長度是 patch_size**2 * cx = x + self.pos_embed[:, 1:, :]
進行隨機遮蔽
self.random_masking(x, mask_ratio)
x = torch.cat((cls_tokens, x), dim=1)
經過上述處理後把帶有類別與位置編碼訊息的1維圖塊們送入Transformer模型(self attention)內
Block(embed_dim, num_heads, mlp_ratio, qkv_bias=True, qk_scale=None, norm_layer=norm_layer) for i in range(depth)])
forward_encoder()
解碼器(decoder)
初始化建立解碼器(decoder)
MAE decoder specifics
解碼器前向傳播
forward_decoder()
損失函數計算與前向傳播
forward_loss()
code
參考資料
gather()
引用自:
repeat()和 expand()
Deep Learning相關筆記
Self-supervised Learning
Object Detection
ViT與Transformer相關
Autoencoder相關