Masked Autoencoders Are Scalable Vision Learners | MAE 阅读笔记&部分翻译

Facebook AI Research的研究者提出了一种简单且可扩展的掩码自编码器(MAE),通过在视觉任务中屏蔽大部分输入并重建,促进了大型模型的训练效率和准确性。MAE利用非对称编码器-解码器结构和轻量级解码器,能在ImageNet-1K数据上显著提升ViT模型性能,展现出在对象检测等任务中的优秀迁移学习能力。

Masked Autoencoders Are Scalable Vision Learners

Author Unit: Facebook AI Research (FAIR)

Authors: Kaiming He ∗ , † ^{∗,†} , Xinlei Chen ∗ ^∗ Saining Xie Yanghao Li Piotr Dollár Ross Girshick

Conference: arXiv:2111.06377v1 [cs.CV] 11 Nov 2021

Paper address: https://arxiv.org/abs/2111.06377

bilibili_limu: https://www.bilibili.com/video/BV1sq4y1q77t

Notion 版本的笔记

假设你的算法特别快,就把标题里面放 efficient;假设你做的东西比较大,就叫 scalable。 —李沐

💡 这里 Autoencoder 中的 Auto 不是指自动的意思,而是“自”,也就是训练样本 x 和标签 y 都是 x 本身。

💡 写论文的时候可以考虑用类似的标题样式,即 ** 是 **,就像这篇文章的标题,很好的将自己的工作浓缩成了一句简短的话。

Abstract

本文表明,masked autoencoders (MAE) 是用于计算机视觉的可扩展自监督学习器。我们的 MAE 方法很 simple:我们屏蔽输入图像的随机块并重建丢失的像素。它基于两个核心设计。首先,我们开发了非对称的编码器 - 解码器架构,其中编码器仅对可见的补丁 patches 子集(没有掩码标记)进行操作,以及一个轻量级的解码器,可从潜在表征 latent representation 和掩码标记 mask tokens 重建原始图像。其次,我们发现屏蔽大部分输入图像(例如 75%)会产生重要且有意义的自监督任务。将这两种设计结合起来使我们能够高效地训练大型模型:我们加速了训练(3 倍或更快)并提高了准确性。我们的可扩展方法允许学

### 关于Masked Autoencoders Are Scalable Vision Learners论文的代码实现 #### PyTorch 实现 针对《Masked Autoencoders Are Scalable Vision Learners》这篇论文,存在多个开源项目提供了基于PyTorch框架下的实现方案。其中一个较为知名的非官方版本可以在GitHub仓库找到[^3]。 以下是使用PyTorch构建MAE模型的核心组件之一——编码器的部分示例代码: ```python import torch.nn as nn from functools import partial from timm.models.vision_transformer import Block, _cfg class Encoder(nn.Module): """Encoder for MAE""" def __init__(self, img_size=224, patch_size=16, embed_dim=768, depth=12, num_heads=12, mlp_ratio=4., norm_layer=partial(nn.LayerNorm, eps=1e-6), **kwargs): super().__init__() self.patch_embed = PatchEmbed(img_size=img_size, patch_size=patch_size, in_chans=3, embed_dim=embed_dim) num_patches = self.patch_embed.num_patches self.cls_token = nn.Parameter(torch.zeros(1, 1, embed_dim)) self.pos_embed = nn.Parameter(torch.zeros(1, num_patches + 1, embed_dim), requires_grad=False) self.blocks = nn.ModuleList([ Block(dim=embed_dim, num_heads=num_heads, mlp_ratio=mlp_ratio, qkv_bias=True, norm_layer=norm_layer) for i in range(depth)]) self.norm = norm_layer(embed_dim) def forward(self, x, mask=None): B, C, H, W = x.shape x = self.patch_embed(x) # (B, L, D) cls_tokens = self.cls_token.expand(B, -1, -1) x = torch.cat((cls_tokens, x), dim=1) pos_embed = self.interpolate_pos_encoding(x.size(-1)-1, H//self.patch_embed.patch_size[0]) x += pos_embed[:, :x.size(1)] if mask is not None: keep_indices = ~mask.bool() x = x * keep_indices.unsqueeze(-1).float() for blk in self.blocks: x = blk(x) x = self.norm(x) return x @staticmethod def interpolate_pos_encoding(N, h): # Implementation details omitted here. pass ``` 此段代码展示了如何定义一个用于自监督学习任务中的视觉Transformer编码器结构。值得注意的是,在前向传播过程中引入了一个`mask`参数来指示哪些位置应该被遮挡掉不参与计算[^4]。 #### TensorFlow/Keras 实现 虽然原始论文主要采用PyTorch作为实验平台,但在TensorFlow社区也有开发者贡献了相应的Keras风格实现方式。下面给出了一种简化版的解码器模块示意代码片段: ```python import tensorflow as tf from tensorflow.keras.layers import Dense, LayerNormalization, Dropout def decoder_block(input_tensor, hidden_units, dropout_rate=.1): """ A single block within the decoder stack. Args: input_tensor: Input tensor from previous layer or embedding output. hidden_units: Number of units in feedforward network inside this block. dropout_rate: Rate at which to drop activations during training. Returns: Output tensor after applying one transformer decoder block operation. """ attention_output = tf.keras.layers.MultiHeadAttention( key_dim=input_tensor.shape[-1], value_dim=input_tensor.shape[-1], num_heads=8)(input_tensor, input_tensor) attention_output = Dropout(dropout_rate)(attention_output) add_attention = tf.keras.layers.Add()([input_tensor, attention_output]) normalized_addition = LayerNormalization()(add_attention) ffn_output = Dense(hidden_units*4, activation="gelu")(normalized_addition) ffn_output = Dropout(dropout_rate)(ffn_output) ffn_output = Dense(hidden_units)(ffn_output) final_output = tf.keras.layers.Add()([normalized_addition, ffn_output]) final_output = LayerNormalization()(final_output) return final_output decoder_input = tf.random.uniform(shape=(batch_size, sequence_length, feature_dimension)) for _ in range(num_decoder_layers): # Repeat according to desired number of layers decoder_input = decoder_block(decoder_input, feature_dimension) ``` 上述代码实现了单层Decoder Block的功能,并可通过循环堆叠多层形成完整的解码网络。需要注意的是实际应用时还需要考虑与特定数据集适配的具体细节以及优化策略等问题[^5]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值