hf_mirrors/swinv2_base_window12to16_192to256.ms_in22k_ft_in1k
Model Introduction
Files & versions
Analysis

Model card for swinv2_base_window12to16_192to256.ms_in22k_ft_in1k

A Swin Transformer V2 image classification model. Pretrained on ImageNet-22k and fine-tuned on ImageNet-1k by paper authors.

Model Details

  • Model Type: Image classification / feature backbone
  • Model Stats:
    • Params (M): 87.9
    • GMACs: 22.0
    • Activations (M): 84.7
    • Image size: 256 x 256
  • Papers:
    • Swin Transformer V2: Scaling Up Capacity and Resolution: https://arxiv.org/abs/2111.09883
  • Original: https://github.com/microsoft/Swin-Transformer
  • Dataset: ImageNet-1k
  • Pretrain Dataset: ImageNet-22k

Model Usage

Image Classification

import torch
import torch_npu
import argparse
from openmind import pipeline, is_torch_npu_available
from PIL import Image
import requests
import timm

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default=None,
    )
    args = parser.parse_args()
    return args

def main():
    args = parse_args()
    model_path = args.model_name_or_path
    
    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"
    
    url = "http://images.cocodataset.org/val2017/000000039769.jpg"
    img = Image.open(requests.get(url, stream=True).raw)
    
    model = timm.create_model("swinv2_base_window12to16_192to256.ms_in22k_ft_in1k", pretrained=True).to(device)
    model = model.eval()

    # get model specific transforms (normalization, resize)
    data_config = timm.data.resolve_model_data_config(model)
    transforms = timm.data.create_transform(**data_config, is_training=False)

    output = model(transforms(img).unsqueeze(0).to(device))  # unsqueeze single image into batch of 1
    top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
    print(top5_class_indices)

if __name__=="__main__":
    main()
    

Model Comparison

Explore the dataset and runtime metrics of this model in timm model results.

Citation

@inproceedings{liu2021swinv2,
  title={Swin Transformer V2: Scaling Up Capacity and Resolution}, 
  author={Ze Liu and Han Hu and Yutong Lin and Zhuliang Yao and Zhenda Xie and Yixuan Wei and Jia Ning and Yue Cao and Zheng Zhang and Li Dong and Furu Wei and Baining Guo},
  booktitle={International Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2022}
}
@misc{rw2019timm,
  author = {Ross Wightman},
  title = {PyTorch Image Models},
  year = {2019},
  publisher = {GitHub},
  journal = {GitHub repository},
  doi = {10.5281/zenodo.4414861}
}