def interpolate_pos_encoding(self, x, w, h):
    npatch = (x.shape[1] - 1)
    N = (self.pos_embed.shape[1] - 1)
    if ((npatch == N) and (w == h)):
        return self.pos_embed
    class_pos_embed = self.pos_embed[:, 0]
    patch_pos_embed = self.pos_embed[:, 1:]
    dim = x.shape[(- 1)]
    w0 = (w // self.patch_embed.patch_size)
    h0 = (h // self.patch_embed.patch_size)
    (w0, h0) = ((w0 + 0.1), (h0 + 0.1))
    patch_pos_embed = nn.functional.interpolate(patch_pos_embed.reshape(1, int(math.sqrt(N)), int(math.sqrt(N)), dim).permute(0, 3, 1, 2), scale_factor=((w0 / math.sqrt(N)), (h0 / math.sqrt(N))), mode='bicubic')
    assert ((int(w0) == patch_pos_embed.shape[(- 2)]) and (int(h0) == patch_pos_embed.shape[(- 1)]))
    patch_pos_embed = patch_pos_embed.permute(0, 2, 3, 1).view(1, (- 1), dim)
    return torch.cat((class_pos_embed.unsqueeze(0), patch_pos_embed), dim=1)
def interpolate_pos_encoding(self, x, w, h):
    npatch = (x.shape[1] - 1)
    N = (self.pos_embed.shape[1] - 1)
    if ((npatch == N) and (w == h)):
        return self.pos_embed
    class_pos_embed = self.pos_embed[:, 0]
    patch_pos_embed = self.pos_embed[:, 1:]
    dim = x.shape[(- 1)]
    w0 = (w // self.patch_embed.patch_size)
    h0 = (h // self.patch_embed.patch_size)
    (w0, h0) = ((w0 + 0.1), (h0 + 0.1))
    patch_pos_embed = nn.functional.interpolate(patch_pos_embed.reshape(1, int(math.sqrt(N)), int(math.sqrt(N)), dim).permute(0, 3, 1, 2), scale_factor=((w0 / math.sqrt(N)), (h0 / math.sqrt(N))), mode='bicubic')
    assert ((int(w0) == patch_pos_embed.shape[(- 2)]) and (int(h0) == patch_pos_embed.shape[(- 1)]))
    patch_pos_embed = patch_pos_embed.permute(0, 2, 3, 1).view(1, (- 1), dim)
    return torch.cat((class_pos_embed.unsqueeze(0), patch_pos_embed), dim=1)