Views
No views yet

1from transformers import AutoImageProcessor, DinatForImageClassification
2from PIL import Image
3import requests
4
5url = "http://images.cocodataset.org/val2017/000000039769.jpg"
6image = Image.open(requests.get(url, stream=True).raw)
7
8feature_extractor = AutoImageProcessor.from_pretrained("shi-labs/dinat-base-in1k-224")
9model = DinatForImageClassification.from_pretrained("shi-labs/dinat-base-in1k-224")
10
11inputs = feature_extractor(images=image, return_tensors="pt")
12outputs = model(**inputs)
13logits = outputs.logits
14# model predicts one of the 1000 ImageNet classes
15predicted_class_idx = logits.argmax(-1).item()
16print("Predicted class:", model.config.id2label[predicted_class_idx])pip install natten to compile on your device, which may take up to a few minutes.
Mac users only have the latter option (no pre-compiled binaries).1@article{hassani2022dilated,
2 title = {Dilated Neighborhood Attention Transformer},
3 author = {Ali Hassani and Humphrey Shi},
4 year = 2022,
5 url = {https://arxiv.org/abs/2209.15001},
6 eprint = {2209.15001},
7 archiveprefix = {arXiv},
8 primaryclass = {cs.CV}
9}