Skip to content

Commit

Permalink
address #330
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidrains committed Oct 4, 2024
1 parent fcb9501 commit 82f2fa7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
setup(
name = 'vit-pytorch',
packages = find_packages(exclude=['examples']),
version = '1.7.12',
version = '1.7.14',
license='MIT',
description = 'Vision Transformer (ViT) - Pytorch',
long_description=long_description,
Expand Down
16 changes: 14 additions & 2 deletions vit_pytorch/regionvit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ def divisible_by(val, d):

# helper classes

class ChanLayerNorm(nn.Module):
def __init__(self, dim, eps = 1e-5):
super().__init__()
self.eps = eps
self.g = nn.Parameter(torch.ones(1, dim, 1, 1))
self.b = nn.Parameter(torch.zeros(1, dim, 1, 1))

def forward(self, x):
var = torch.var(x, dim = 1, unbiased = False, keepdim = True)
mean = torch.mean(x, dim = 1, keepdim = True)
return (x - mean) / (var + self.eps).sqrt() * self.g + self.b

class Downsample(nn.Module):
def __init__(self, dim_in, dim_out):
super().__init__()
Expand Down Expand Up @@ -212,10 +224,10 @@ def __init__(
if tokenize_local_3_conv:
self.local_encoder = nn.Sequential(
nn.Conv2d(3, init_dim, 3, 2, 1),
nn.LayerNorm(init_dim),
ChanLayerNorm(init_dim),
nn.GELU(),
nn.Conv2d(init_dim, init_dim, 3, 2, 1),
nn.LayerNorm(init_dim),
ChanLayerNorm(init_dim),
nn.GELU(),
nn.Conv2d(init_dim, init_dim, 3, 1, 1)
)
Expand Down

0 comments on commit 82f2fa7

Please sign in to comment.