Skip to content

Commit

Permalink
fix feature maps in Nest, thanks to @MarkYangjiayi
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidrains committed Jan 22, 2022
1 parent 1cc0f18 commit c1528ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 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 = '0.26.3',
version = '0.26.4',
license='MIT',
description = 'Vision Transformer (ViT) - Pytorch',
author = 'Phil Wang',
Expand Down
8 changes: 5 additions & 3 deletions vit_pytorch/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ def __init__(

seq_len = (fmap_size // blocks) ** 2 # sequence length is held constant across heirarchy
hierarchies = list(reversed(range(num_hierarchies)))
mults = [2 ** i for i in hierarchies]
mults = [2 ** i for i in reversed(hierarchies)]

layer_heads = list(map(lambda t: t * heads, mults))
layer_dims = list(map(lambda t: t * dim, mults))
last_dim = layer_dims[-1]

layer_dims = [*layer_dims, layer_dims[-1]]
dim_pairs = zip(layer_dims[:-1], layer_dims[1:])
Expand All @@ -157,10 +158,11 @@ def __init__(
Aggregate(dim_in, dim_out) if not is_last else nn.Identity()
]))


self.mlp_head = nn.Sequential(
LayerNorm(dim),
LayerNorm(last_dim),
Reduce('b c h w -> b c', 'mean'),
nn.Linear(dim, num_classes)
nn.Linear(last_dim, num_classes)
)

def forward(self, img):
Expand Down

0 comments on commit c1528ac

Please sign in to comment.