# KeyError when loading any dinov2 model

**URL:** <https://discuss.huggingface.co/t/keyerror-when-loading-any-dinov2-model/49380>\
**Category:** 🤗Transformers\
**Created:** [August 3, 2023, 6:27pm UTC](https://discuss.huggingface.co/t/keyerror-when-loading-any-dinov2-model/49380 "2023-08-03T18:27:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kinyugo](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/kinyugo/32/18213_2.png) [@kinyugo](https://discuss.huggingface.co/u/kinyugo)\
**Post date:** [August 3, 2023, 6:27pm UTC](https://discuss.huggingface.co/t/keyerror-when-loading-any-dinov2-model/49380/1 "2023-08-03T18:27:27Z")

</div>

I am trying to load facebook’s dinov2 models as shown below. However I am getting `KeyError: 'dinov2'` error. I have updated my transformers library to the latest version and also made sure that all packages used in the [github dinov2 repo](https://github.com/facebookresearch/dinov2) are installed. I have also tried searching for a model class within transformers but could not find one.

## Script

* * *

```python
from transformers import AutoImageProcessor, AutoModel
from PIL import Image
import requests

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

processor = AutoImageProcessor.from_pretrained('facebook/dinov2-giant')
model = AutoModel.from_pretrained('facebook/dinov2-giant')

inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
last_hidden_states = outputs.last_hidden_state

```

## Environment

* * *

- `transformers` version: 4.31.0
- Platform: Linux-5.4.0-139-generic-x86\_64-with-glibc2.31
- Python version: 3.11.4
- Huggingface\_hub version: 0.16.4
- Safetensors version: 0.3.1
- Accelerate version: 0.21.0
- Accelerate config: - compute\_environment: LOCAL\_MACHINE
  - distributed\_type: NO
  - mixed\_precision: fp16
  - use\_cpu: False
  - num\_processes: 1
  - machine\_rank: 0
  - num\_machines: 1
  - gpu\_ids: all
  - rdzv\_backend: static
  - same\_network: True
  - main\_training\_function: main
  - downcast\_bf16: no
  - tpu\_use\_cluster: False
  - tpu\_use\_sudo: False
  - tpu\_env: 

- PyTorch version (GPU?): 2.0.1+cu117 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: False
- Using distributed or parallel set-up in script?: False

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [August 4, 2023, 7:20am UTC](https://discuss.huggingface.co/t/keyerror-when-loading-any-dinov2-model/49380/2 "2023-08-04T07:20:05Z")

</div>

Hi,

You need to install Transformers from source for now:

```auto
pip install -q git+https://github.com/huggingface/transformers.git

```
