Skip to content

Cannot load the pretrained vit model offline using timm.create_model #2061

@dongdongtong

Description

@dongdongtong

I'm trying to load pretrained ViTs using timm and huggingface pretrained models offline. I download the pretrained weights from huggingface mannualy. However, when loading pretrained vit_tiny_patch16_224 and vit_small_patch16_224 weights via timm.create_model, I get the following error:
KeyError: 'embedding/kernel is not a file in the archive'.
It seems that the _load_weights function of vision_transformer.py is troublesome.

To Reproduce
Steps to reproduce the behavior:

  1. Download the pretrained weights (pytorch.bin) from huggingface and put it into the proper location.
  2. using timm create_model function to load the pretrained weights:
    timm.create_model( "vit_tiny_patch16_224", pretrained=True, pretrained_cfg_overlay=dict( file="/home/your_path/.cache/huggingface/hub/models--timm--vit_tiny_patch16_224.augreg_in21k_ft_in1k/pytorch_model.bin") )

Expected behavior
load the pretrained weights successfully.

Screenshots
image

Desktop (please complete the following information):

  • OS: [Ubuntu 22.04]
  • pytorch: 1.11.0
  • timm: 0.9.12

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions