不管大家如何嘲讽,Google Brain和Facebook AI的地位无可撼动。
和Google的MLP-Mixer的区别主要有三点:
# No norm layer class Affine(nn.Module): def __init__(self, dim): super().__init__() self.alpha = nn.Parameter(torch.ones(dim)) self.beta = nn.Parameter(torch.zeros(dim)) def forward(self, x): return self.alpha * x + self.beta # MLP on channels class Mlp(nn.Module): def __init__(self, dim): super().__init__() self.fc1 = nn.Linear(dim, 4 * dim) self.act = nn.GELU() self.fc2 = nn.Linear(4 * dim, dim) def forward(self, x): x = self.fc1(x) x = self.act(x) x = self.fc2(x) return x # ResMLP blocks: a linear between patches + a MLP to process them independently class ResMLP_BLocks(nn.Module): def __init__(self, nb_patches ,dim, layerscale_init): super().__init__() self.affine_1 = Affine(dim) self.affine_2 = Affine(dim) self.linear_patches = nn.Linear(nb_patches, nb_patches) #Linear layer on patches self.mlp_channels = Mlp(dim) #MLP on channels self.layerscale_1 = nn.Parameter(layerscale_init * torch.ones((dim))) #LayerScale self.layerscale_2 = nn.Parameter(layerscale_init * torch.ones((dim))) # parameters def forward(self, x): res_1 = self.linear_patches(self.affine_1(x).transpose(1,2)).transpose(1,2)) x = x + self.layerscale_1 * res_1 res_2 = self.mlp_channels(self.affine_2(x)) x = x + self.layerscale_2 * res_2 return x # ResMLP model: Stacking the full network class ResMLP_models(nn.Module): def __init__(self, dim, depth, nb_patches, layerscale_init, num_classes): super().__init__() self.patch_projector = Patch_projector() self.blocks = nn.ModuleList([ ResMLP_BLocks(nb_patches ,dim, layerscale_init) for i in range(depth)]) self.affine = Affine(dim) self.linear_classifier = nn.Linear(dim, num_classes) def forward(self, x): B, C, H, W = x.shape x = self.patch_projector(x) for blk in self.blocks: x = blk(x) x = self.affine(x) x = x.mean(dim=1).reshape(B,-1) #average pooling return self.linear_classifier(x)
走来走去,怕是最后都要走回当年提取局部patch的斑点或者特征点,再用各种编码方式进行aggregate的老路了。
BoW is all you need。
本站所有内容均为互联网搜索引擎提供的公开搜索信息,本站不存储任何数据与内容,任何内容与数据均与本站无关,如有需要请联系相关搜索引擎包括但不限于百度,google,bing,sogou 等
© 2025 tinynews.org All Rights Reserved. 百科问答小站 版权所有