OWG
/

ONNX
English
deit
File size: 1,142 Bytes
e3572de
486bcbc
 
 
 
e3572de
486bcbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
language: en
tags:
- deit
license: apache-2.0
---

# DeiT

## Model description

 DeiT proposed in [this paper](https://arxiv.org/abs/2012.12877) are more efficiently trained transformers for image classification, requiring far less data and far less computing resources compared to the original ViT models.

## Original implementation

Follow [this link](https://huggingface.co/docs/transformers/main/en/model_doc/deit#deit) to see the original implementation.

## How to use

```{python}
from onnxruntime import InferenceSession
from transformers import DeiTFeatureExtractor, DeiTForImageClassification
import torch
from PIL import Image
import requests

torch.manual_seed(3)
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)

feature_extractor = DeiTFeatureExtractor.from_pretrained("facebook/deit-base-distilled-patch16-224")
inputs = feature_extractor(images=image, return_tensors="np")
session = InferenceSession("onnx/model.onnx")

# ONNX Runtime expects NumPy arrays as input
outputs = session.run(output_names=["last_hidden_state"], input_feed=dict(inputs))
```