Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into master-patched
Browse files Browse the repository at this point in the history
  • Loading branch information
xwang233 committed Nov 7, 2024
2 parents 5f54681 + eb94efb commit 3ce8cc1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion timm/models/deit.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ def set_distilled_training(self, enable=True):
def _pos_embed(self, x):
if self.dynamic_img_size:
B, H, W, C = x.shape
prev_grid_size = self.patch_embed.grid_size
pos_embed = resample_abs_pos_embed(
self.pos_embed,
(H, W),
new_size=(H, W),
old_size=prev_grid_size,
num_prefix_tokens=0 if self.no_embed_class else self.num_prefix_tokens,
)
x = x.view(B, -1, C)
Expand Down
4 changes: 3 additions & 1 deletion timm/models/eva.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,11 @@ def _pos_embed(self, x) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
if self.dynamic_img_size:
B, H, W, C = x.shape
if self.pos_embed is not None:
prev_grid_size = self.patch_embed.grid_size
pos_embed = resample_abs_pos_embed(
self.pos_embed,
(H, W),
new_size=(H, W),
old_size=prev_grid_size,
num_prefix_tokens=self.num_prefix_tokens,
)
else:
Expand Down
4 changes: 3 additions & 1 deletion timm/models/vision_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,11 @@ def _pos_embed(self, x: torch.Tensor) -> torch.Tensor:

if self.dynamic_img_size:
B, H, W, C = x.shape
prev_grid_size = self.patch_embed.grid_size
pos_embed = resample_abs_pos_embed(
self.pos_embed,
(H, W),
new_size=(H, W),
old_size=prev_grid_size,
num_prefix_tokens=0 if self.no_embed_class else self.num_prefix_tokens,
)
x = x.view(B, -1, C)
Expand Down

0 comments on commit 3ce8cc1

Please sign in to comment.