Views
No views yet

1from transformers import AutoImageProcessor, ConvNextV2ForImageClassification
2import torch
3from datasets import load_dataset
4
5dataset = load_dataset("huggingface/cats-image")
6image = dataset["test"]["image"][0]
7
8preprocessor = AutoImageProcessor.from_pretrained("facebook/convnextv2-large-22k-384")
9model = ConvNextV2ForImageClassification.from_pretrained("facebook/convnextv2-large-22k-384")
10
11inputs = preprocessor(image, return_tensors="pt")
12
13with torch.no_grad():
14 logits = model(**inputs).logits
15
16# model predicts one of the 1000 ImageNet classes
17predicted_label = logits.argmax(-1).item()
18print(model.config.id2label[predicted_label]),1@article{DBLP:journals/corr/abs-2301-00808,
2 author = {Sanghyun Woo and
3 Shoubhik Debnath and
4 Ronghang Hu and
5 Xinlei Chen and
6 Zhuang Liu and
7 In So Kweon and
8 Saining Xie},
9 title = {ConvNeXt {V2:} Co-designing and Scaling ConvNets with Masked Autoencoders},
10 journal = {CoRR},
11 volume = {abs/2301.00808},
12 year = {2023},
13 url = {https://doi.org/10.48550/arXiv.2301.00808},
14 doi = {10.48550/arXiv.2301.00808},
15 eprinttype = {arXiv},
16 eprint = {2301.00808},
17 timestamp = {Tue, 10 Jan 2023 15:10:12 +0100},
18 biburl = {https://dblp.org/rec/journals/corr/abs-2301-00808.bib},
19 bibsource = {dblp computer science bibliography, https://dblp.org}
20}