    def inflate_weights(self):
        """
        Inflate the swin2d parameters to swin3d.
        The differences between swin3d and swin2d mainly lie in an extra
        axis. To utilize the pretrained parameters in 2d model,
        the weight of swin2d models should be inflated to fit in the shapes of
        the 3d counterpart.

        """
        checkpoint = torch.load(self.pretrained, map_location="cpu")
        state_dict = checkpoint["model"]

        # delete relative_position_index since we always re-init it
        relative_position_index_keys = [k for k in state_dict.keys() if "relative_position_index" in k]
        for k in relative_position_index_keys:
            del state_dict[k]

        # delete attn_mask since we always re-init it
        attn_mask_keys = [k for k in state_dict.keys() if "attn_mask" in k]
        for k in attn_mask_keys:
            del state_dict[k]

        state_dict["patch_embed.proj.weight"] =\
            state_dict["patch_embed.proj.weight"].unsqueeze(2).repeat(1, 1, self.patch_size[0], 1, 1) \
            / self.patch_size[0]

        # bicubic interpolate relative_position_bias_table if not match
        relative_position_bias_table_keys = [k for k in state_dict.keys() if "relative_position_bias_table" in k]
        for k in relative_position_bias_table_keys:
            relative_position_bias_table_pretrained = state_dict[k]
            # pylint: disable=E1136
            relative_position_bias_table_current = self.state_dict()[k]
            l1, nh1 = relative_position_bias_table_pretrained.size()
            l2, nh2 = relative_position_bias_table_current.size()
            l2 = (2*self.window_size[1]-1) * (2*self.window_size[2]-1)
            wd = self.window_size[0]
            if nh1 != nh2:
                logging.info("Error in loading %s, passing", k)
            else:
                if l1 != l2:
                    s1 = int(l1 ** 0.5)
                    relative_position_bias_table_pretrained_resized = torch.nn.functional.interpolate(
                        relative_position_bias_table_pretrained.permute(1, 0).view(1, nh1, s1, s1),
                        size=(2*self.window_size[1]-1, 2*self.window_size[2]-1),
                        mode="bicubic")
                    relative_position_bias_table_pretrained =\
                        relative_position_bias_table_pretrained_resized.view(nh2, l2).permute(1, 0)
            state_dict[k] = relative_position_bias_table_pretrained.repeat(2*wd-1, 1)

        msg = self.load_state_dict(state_dict, strict=False)
        logging.info(msg)
        logging.info("=> loaded successfully %s", self.pretrained)
        del checkpoint
        torch.cuda.empty_cache()
Inflate the swin2d parameters to swin3d.
The differences between swin3d and swin2d mainly lie in an extra
axis. To utilize the pretrained parameters in 2d model,
the weight of swin2d models should be inflated to fit in the shapes of
the 3d counterpart.
towhee/models/video_swin_transformer/video_swin_transformer.py