Instructions to use timm/swinv2_tiny_window16_256.ms_in1k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use timm/swinv2_tiny_window16_256.ms_in1k with timm:
import timm model = timm.create_model("hf_hub:timm/swinv2_tiny_window16_256.ms_in1k", pretrained=True) - Transformers
How to use timm/swinv2_tiny_window16_256.ms_in1k with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="timm/swinv2_tiny_window16_256.ms_in1k") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("timm/swinv2_tiny_window16_256.ms_in1k", dtype="auto") - Notebooks
- Google Colab
- Kaggle
The issue of model-parameter mismatch.
I download the file 'model_safetensors' from the files and versions. However, when I use 'timm.create_model('swinv2_tiny_window16_256.ms_in1k', checkpoint_path='./model.safetensors') to load this mode, there is an error stating that some unexpected keys in the state_dict, such as 'layers.0.blocks.1.attn_mask' and 'layers.1.blocks.1.attn_mask'.
@JeeXR when you load via checkpoint_path it assumes an exact match between model and checkpoint. There are some pretrained weights were adaptation is done on load, attn_mask were changed from being persistent to non-persistent at some point.
You need to override the pretrained location with a local file as in this example
https://github.com/huggingface/pytorch-image-models/discussions/2069#discussioncomment-8532295
timm.create_model(
'swinv2_tiny_window16_256.ms_in1k,
pretrained=True,
pretrained_cfg_overlay=dict(file='./model.safetensors'),
)