Skip to content

Commit

Permalink
seeing a signal with dual patchnorm in another repository, fully inco…
Browse files Browse the repository at this point in the history
…rporate
  • Loading branch information
lucidrains committed Feb 6, 2023
1 parent bdaf2d1 commit 46dcaf2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name = 'vit-pytorch',
packages = find_packages(exclude=['examples']),
version = '1.0.0',
version = '1.0.1',
license='MIT',
description = 'Vision Transformer (ViT) - Pytorch',
long_description_content_type = 'text/markdown',
Expand Down
2 changes: 2 additions & 0 deletions vit_pytorch/learnable_memory_vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def __init__(self, *, image_size, patch_size, num_classes, dim, depth, heads, ml

self.to_patch_embedding = nn.Sequential(
Rearrange('b c (h p1) (w p2) -> b (h w) (p1 p2 c)', p1 = patch_height, p2 = patch_width),
nn.LayerNorm(patch_dim),
nn.Linear(patch_dim, dim),
nn.LayerNorm(dim)
)

self.pos_embedding = nn.Parameter(torch.randn(1, num_patches + 1, dim))
Expand Down
7 changes: 6 additions & 1 deletion vit_pytorch/twins_svt.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ def __init__(self, *, dim, dim_out, patch_size):
self.dim = dim
self.dim_out = dim_out
self.patch_size = patch_size
self.proj = nn.Conv2d(patch_size ** 2 * dim, dim_out, 1)

self.proj = nn.Sequential(
LayerNorm(patch_size ** 2 * dim),
nn.Conv2d(patch_size ** 2 * dim, dim_out, 1),
LayerNorm(dim_out)
)

def forward(self, fmap):
p = self.patch_size
Expand Down
2 changes: 2 additions & 0 deletions vit_pytorch/vit_with_patch_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def __init__(self, *, image_size, patch_size, num_classes, dim, depth, heads, ml

self.to_patch_embedding = nn.Sequential(
Rearrange('b c (h p1) (w p2) -> b (h w) (p1 p2 c)', p1 = patch_height, p2 = patch_width),
nn.LayerNorm(patch_dim),
nn.Linear(patch_dim, dim),
nn.LayerNorm(dim)
)

self.pos_embedding = nn.Parameter(torch.randn(1, num_patches + 1, dim))
Expand Down

0 comments on commit 46dcaf2

Please sign in to comment.