81f1e3e3创建于 2024年11月20日历史提交

license: apache-2.0 tags:

  • generated_from_trainer datasets:
  • cifar100 metrics:
  • accuracy model-index:
  • name: swin-small-finetuned-cifar100 results:
    • task: name: Image Classification type: image-classification dataset: name: cifar100 type: cifar100 args: cifar100 metrics:
      • name: Accuracy type: accuracy value: 0.8938 pipeline_tag: image-classification frameworks:
  • PyTorch library_name: openmind hardwares:
  • NPU language:
  • zh

swin-small-finetuned-cifar100

This model is a fine-tuned version of GuangxiAICC/swin-small-patch4-window7-224 on the cifar100 dataset. It achieves the following results on the evaluation set:

  • Loss: 0.6281
  • Accuracy: 0.8938

Model description

More information needed

Intended uses & limitations

More information needed

Training and evaluation data

More information needed

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 4e-05
  • train_batch_size: 16
  • eval_batch_size: 16
  • seed: 42
  • gradient_accumulation_steps: 4
  • total_train_batch_size: 64
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lr_scheduler_type: linear
  • lr_scheduler_warmup_ratio: 0.1
  • num_epochs: 20

Training results

Training Loss Epoch Step Validation Loss Accuracy
0.72 1.0 781 0.6691 0.8077
0.6944 2.0 1562 0.4797 0.8495
0.2794 3.0 2343 0.4338 0.869
0.2569 4.0 3124 0.4263 0.879
0.1417 5.0 3905 0.4385 0.8819
0.0961 6.0 4686 0.4720 0.8854
0.0584 7.0 5467 0.4941 0.885
0.0351 8.0 6248 0.5253 0.885
0.0107 9.0 7029 0.5598 0.8887
0.0118 10.0 7810 0.5998 0.8858
0.0097 11.0 8591 0.5957 0.8941
0.0044 12.0 9372 0.6237 0.8912
0.0013 13.0 10153 0.6286 0.8929
0.0102 14.0 10934 0.6281 0.8938

inference

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

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()
    if args.model_name_or_path:
        model_path = args.model_name_or_path
    else:
        model_path = snapshot_download(
            "GuangxiAICC/swin-small-finetuned-cifar100",
            revision="main",
            ignore_patterns=["*.h5", "*.ot", "*.msgpack"],
        )
    
    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"
    
    url = "http://images.cocodataset.org/val2017/000000039769.jpg"
    image = Image.open(requests.get(url, stream=True).raw)
    processor = AutoImageProcessor.from_pretrained(model_path)
    model = AutoModel.from_pretrained(model_path).to(device)

    inputs = processor(images=image, return_tensors="pt").to(device)
    outputs = model(**inputs)
    print("Predicted class:", outputs)

if __name__=="__main__":
    main()

Framework versions

  • Transformers 4.20.1
  • Pytorch 2.1.0-npu
  • Datasets 2.1.0
  • Tokenizers 0.12.1