Update metaformers.py

pull/1647/head
Fredo Guan 2 years ago
parent 09d1ea628d
commit 473403d905

@ -216,7 +216,7 @@ cfgs_v2 = generate_default_cfgs({
url='https://huggingface.co/sail/dl/resolve/main/caformer/caformer_b36_in21k.pth', url='https://huggingface.co/sail/dl/resolve/main/caformer/caformer_b36_in21k.pth',
num_classes=21841), num_classes=21841),
}) })
'''
class Downsampling(nn.Module): class Downsampling(nn.Module):
""" """
Downsampling implemented by a layer of convolution. Downsampling implemented by a layer of convolution.
@ -255,15 +255,15 @@ class Downsampling(nn.Module):
self.post_norm = post_norm(out_channels) if post_norm else nn.Identity() self.post_norm = post_norm(out_channels) if post_norm else nn.Identity()
def forward(self, x): def forward(self, x):
print(x.shape) #print(x.shape)
x = self.pre_norm(x) x = self.pre_norm(x)
print(x.shape) #print(x.shape)
x = self.conv(x) x = self.conv(x)
print(x.shape) #print(x.shape)
x = self.post_norm(x.permute(0, 2, 3, 1)).permute(0, 3, 1, 2) x = self.post_norm(x.permute(0, 2, 3, 1)).permute(0, 3, 1, 2)
print(x.shape) #print(x.shape)
return x return x
'''
class Scale(nn.Module): class Scale(nn.Module):
""" """
Scale vector by element multiplications. Scale vector by element multiplications.
@ -363,7 +363,7 @@ class RandomMixing(nn.Module):
x = x.reshape(B, H, W, C) x = x.reshape(B, H, W, C)
return x return x
'''
class LayerNormGeneral(nn.Module): class LayerNormGeneral(nn.Module):
r""" General LayerNorm for different situations. r""" General LayerNorm for different situations.
@ -462,7 +462,7 @@ class LayerNormGeneral(nn.Module):
if self.use_bias: if self.use_bias:
x = x + self.bias x = x + self.bias
return x return x
'''
class SepConv(nn.Module): class SepConv(nn.Module):
r""" r"""
Inverted separable convolution from MobileNetV2: https://arxiv.org/abs/1801.04381. Inverted separable convolution from MobileNetV2: https://arxiv.org/abs/1801.04381.

Loading…
Cancel
Save