Views
No views yet
1from transformers import BitImageProcessor, BitForImageClassification
2import torch
3from datasets import load_dataset
4
5dataset = load_dataset("huggingface/cats-image")
6image = dataset["test"]["image"][0]
7
8feature_extractor = BitImageProcessor.from_pretrained("google/bit-50")
9model = BitForImageClassification.from_pretrained("google/bit-50")
10
11inputs = feature_extractor(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
19>>> tabby, tabby cat1@misc{https://doi.org/10.48550/arxiv.1912.11370,
2 doi = {10.48550/ARXIV.1912.11370},
3
4 url = {https://arxiv.org/abs/1912.11370},
5
6 author = {Kolesnikov, Alexander and Beyer, Lucas and Zhai, Xiaohua and Puigcerver, Joan and Yung, Jessica and Gelly, Sylvain and Houlsby, Neil},
7
8 keywords = {Computer Vision and Pattern Recognition (cs.CV), Machine Learning (cs.LG), FOS: Computer and information sciences, FOS: Computer and information sciences},
9
10 title = {Big Transfer (BiT): General Visual Representation Learning},
11
12 publisher = {arXiv},
13
14 year = {2019},
15
16 copyright = {arXiv.org perpetual, non-exclusive license}
17}
18