Update vit_patch_generator.py
Browse files118 unmodified lines119120121122123124125126127128156 unmodified lines285286287288289290291292293294295296297298299300301302118 unmodified lines'pos_embed',]def _load_from_state_dict(self, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs):if self.abs_pos:self._load_embed(state_dict[f'{prefix}pos_embed'], self.pos_embed)def _load_embed(self, src_embed: torch.Tensor, targ_embed: nn.Parameter):if src_embed.shape != targ_embed.shape:src_size = int(math.sqrt(src_embed.shape[1]))156 unmodified lines**factory)self.patch_size = patch_sizedef _load_from_state_dict(self, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs):if self.bias is not None:self.bias.data.copy_(state_dict[f'{prefix}bias'])chk_weight = state_dict[f'{prefix}weight']if chk_weight.shape != self.weight.shape:src_patch_size = int(math.sqrt(chk_weight.shape[1] // 3))assert (src_patch_size ** 2) * 3 == chk_weight.shape[1], 'Unable to interpolate non-square patch size'chk_weight = rearrange(chk_weight, 'b (c h w) -> b c h w', c=3, h=src_patch_size, w=src_patch_size)chk_weight = F.interpolate(chk_weight, size=(self.patch_size, self.patch_size), mode='bicubic', align_corners=True, antialias=False)chk_weight = rearrange(chk_weight, 'b c h w -> b (c h w)')self.weight.data.copy_(chk_weight)118 unmodified lines119120121122123124156 unmodified lines281282283118 unmodified lines'pos_embed',]def _load_embed(self, src_embed: torch.Tensor, targ_embed: nn.Parameter):if src_embed.shape != targ_embed.shape:src_size = int(math.sqrt(src_embed.shape[1]))156 unmodified lines**factory)self.patch_size = patch_size
vit_patch_generator.py-19