open-mmlab / mmpretrain

OpenMMLab Pre-training Toolbox and Benchmark
https://mmpretrain.readthedocs.io/en/latest/
Apache License 2.0
3.4k stars 1.06k forks source link

how to load pretrained weight for swin transformer. #524

Closed XuKun2424 closed 2 years ago

XuKun2424 commented 2 years ago

推荐使用英语模板 General question,以便你的问题帮助更多人。

首先确认以下内容

描述你遇到的问题

self = SwinTransformer(**extra_config) self._load_from_state_dict()

相关信息

  1. pip list | grep "mmcv\|mmcls\|^torch" 命令的输出 [填写这里]
  2. 如果你修改了,或者使用了新的配置文件,请在这里写明
    [填写这里]
  3. 如果你是在训练过程中遇到的问题,请填写完整的训练日志和报错信息 [填写这里]
  4. 如果你对 mmcls 文件夹下的代码做了其他相关的修改,请在这里写明 [填写这里]
Ezra-Yu commented 2 years ago

refer to this article

Inherit a base swin-transformer configuration file, and add this.

_base_ = ['../_base_/models/swin_transformer/tiny_224.py']

  backbone=dict(
      init_cfg = dict(
          type='Pretrained', 
          checkpoint="https://download.openmmlab.com/mmclassification/v0/swin-transformer/swin_tiny_224_b16x64_300e_imagenet_20210616_090925-66df6be6.pth", 
          prefix='backbone')
  )
XuKun2424 commented 2 years ago

refer to this article

Inherit a base swin-transformer configuration file, and add this.

_base_ = ['../_base_/models/swin_transformer/tiny_224.py']

  backbone=dict(
      init_cfg = dict(
          type='Pretrained', 
          checkpoint="https://download.openmmlab.com/mmclassification/v0/swin-transformer/swin_tiny_224_b16x64_300e_imagenet_20210616_090925-66df6be6.pth", 
          prefix='backbone')
  )

Haha, thank my brother