A CSP-DarkNet (Cross-Stage-Partial) image classification model. Trained on ImageNet-1k in timm using recipe template described below.
Recipe details:
RA recipe. Inspired by and evolved from EfficientNet RandAugment recipes. Published as B recipe in ResNet Strikes Back.
# from urllib.request import urlopen
from PIL import Image
import timm
import argparse
import torch
from openmind import is_torch_npu_available
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--model_name_or_path",
type=str,
help="Path to the model file",
default=None,
)
args = parser.parse_args()
return args
if __name__ == '__main__':
args = parse_args()
if is_torch_npu_available():
device = "npu:0"
else:
device = "cpu"
model_path = args.model_name_or_path
img = model_path + "/Img/beignets-task-guide.png"
img = Image.open(img)
model_name = 'cspdarknet53.ra_in1k'
checkpoint_path = model_path + '/pytorch_model.bin'
model = timm.create_model(model_name, pretrained=False, checkpoint_path=checkpoint_path).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_probabilities", top5_probabilities)
# top5_probabilities tensor([[12.7346, 12.3356, 7.7930, 5.9564, 5.0362]], device='npu:0',
# grad_fn=<TopkBackward0>)
print("top5_class_indices", top5_class_indices)
# top5_class_indices tensor([[960, 969, 967, 968, 505]], device='npu:0')
Explore the dataset and runtime metrics of this model in timm model results.
@article{Wang2019CSPNetAN,
title={CSPNet: A New Backbone that can Enhance Learning Capability of CNN},
author={Chien-Yao Wang and Hong-Yuan Mark Liao and I-Hau Yeh and Yueh-Hua Wu and Ping-Yang Chen and Jun-Wei Hsieh},
journal={2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW)},
year={2019},
pages={1571-1580}
}@article{Redmon2018YOLOv3AI,
title={YOLOv3: An Incremental Improvement},
author={Joseph Redmon and Ali Farhadi},
journal={ArXiv},
year={2018},
volume={abs/1804.02767}
}@inproceedings{wightman2021resnet,
title={ResNet strikes back: An improved training procedure in timm},
author={Wightman, Ross and Touvron, Hugo and Jegou, Herve},
booktitle={NeurIPS 2021 Workshop on ImageNet: Past, Present, and Future}
}@misc{rw2019timm,
author = {Ross Wightman},
title = {PyTorch Image Models},
year = {2019},
publisher = {GitHub},
journal = {GitHub repository},
doi = {10.5281/zenodo.4414861},
howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
}