Skip to content

Commit ef00378

Browse files
committed
Add update_feat_shape to dinov3 rope. Toggle fix_input_size bool to True on dinov3 pretrained_cfg so correct default size set if dynamic_img_size turned off. Fix #2593
1 parent 6ee68e5 commit ef00378

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

timm/layers/pos_embed_sincos.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,11 @@ def _cache_embed(self, feat_shape: List[int]):
11121112
self.register_buffer("pos_embed_cached", rope_embed, persistent=False)
11131113
self.feat_shape = feat_shape
11141114

1115+
def update_feat_shape(self, feat_shape: List[int]):
1116+
if self.feat_shape is not None and feat_shape != self.feat_shape:
1117+
# only update if feat_shape was set (valid cache) and different from previous value
1118+
self._cache_embed(feat_shape)
1119+
11151120
def get_embed(self, shape: Optional[List[int]] = None) -> torch.Tensor:
11161121
"""Generate rope_embed matching DINOv3 RopePositionEmbedding numerics.
11171122

timm/models/eva.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ def _dinov3_cfg(url: str = '', **kwargs) -> Dict[str, Any]:
13021302
return {
13031303
'url': url,
13041304
'num_classes': 0, 'input_size': (3, 256, 256), 'pool_size': None,
1305-
'crop_pct': 1.0, 'interpolation': 'bicubic', 'min_input_size': (3, 128, 128),
1305+
'crop_pct': 1.0, 'interpolation': 'bicubic', 'fixed_input_size': True,
13061306
'mean': IMAGENET_DEFAULT_MEAN, 'std': IMAGENET_DEFAULT_STD,
13071307
'first_conv': 'patch_embed.proj', 'classifier': 'head',
13081308
'license': 'dinov3', **kwargs

0 commit comments

Comments
 (0)