---
title: facebook-dinov2
canonical_url: "https://www.modelscope.cn/models/anyforge/facebook-dinov2"
md_url: "https://www.modelscope.cn/models/anyforge/facebook-dinov2.md"
repository: anyforge/facebook-dinov2
chinese_name: "facebook-dinov2系列模型"
last_updated: 2025-05-29
license: "Apache License 2.0"
pipeline_tag: video-embedding
tasks:
  - video-embedding
  - image-classification
  - product-retrieval-embedding
parameters: 3.1B
tensor_type:
  - F32
library_name:
  - transformer
  - safetensors
  - pytorch
frameworks:
  - Pytorch
downloads: 863
stars: 1
tags:
  - "图片表征"
  - DINO
  - "Image Feature Extraction"
---

# facebook-dinov2

> facebook-dinov2 - anyforge 在 ModelScope 开源的模型。使用DINOv2方法训练的视觉转换器 (ViT) 模型

anyforge/facebook-dinov2 是 ModelScope 魔搭社区上的 3.1B 参数video-embedding、image-classification、product-retrieval-embedding模型，采用 Apache License 2.0 许可。

- **Repository**: anyforge/facebook-dinov2
- **License**: Apache License 2.0
- **Tasks**: video-embedding, image-classification, product-retrieval-embedding
- **Parameters**: 3.1B
- **Tags**: 图片表征, DINO, Image Feature Extraction
- **Downloads**: 863
- **Stars**: 1
- **Last updated**: 2025-05-29

Source: https://www.modelscope.cn/models/anyforge/facebook-dinov2

---

## 说明

使用DINOv2方法训练的视觉转换器 (ViT) 模型

视觉转换器 (ViT) 是一种以自监督方式对大量图像进行预训练的转换器编码器模型 (类似BERT)。

图像作为线性嵌入的固定大小的补丁序列呈现给模型。还将 [CLS] 令牌添加到序列的开头，以将其用于分类任务。在将序列馈送到变压器编码器的层之前，还添加绝对位置嵌入。

请注意，此模型不包括任何微调头。

通过预训练模型，它学习图像的内部表示，然后可以用来提取对下游任务有用的特征: 例如，如果您有一个标记图像的数据集，您可以通过在预训练的编码器上放置线性层来训练标准分类器。通常将线性层放置在 [CLS] 令牌的顶部，因为该令牌的最后隐藏状态可以被视为整个图像的表示。

### SDK下载

```bash
#安装ModelScope
pip install modelscope
```

```python
#SDK模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('anyforge/facebook-dinov2')
```

### Git下载

```
#Git模型下载
git clone https://www.modelscope.cn/anyforge/facebook-dinov2.git
```

### 使用

```
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-base')
model = AutoModel.from_pretrained('facebook/dinov2-base')

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

### 如果需要向量
emb = outputs.pooler_output
```

<p style="color: lightgrey;">如果您是本模型的贡献者，我们邀请您根据<a href="https://modelscope.cn/docs/ModelScope%E6%A8%A1%E5%9E%8B%E6%8E%A5%E5%85%A5%E6%B5%81%E7%A8%8B%E6%A6%82%E8%A7%88" style="color: lightgrey; text-decoration: underline;">模型贡献文档</a>，及时完善模型卡片内容。</p>
