---
title: cv_stable-diffusion-v2_image-feature
canonical_url: "https://www.modelscope.cn/models/damo/cv_stable-diffusion-v2_image-feature"
md_url: "https://www.modelscope.cn/models/damo/cv_stable-diffusion-v2_image-feature.md"
repository: damo/cv_stable-diffusion-v2_image-feature
chinese_name: "DIFT基于扩散模型的图像特征抽取"
last_updated: 2023-11-17
license: "Apache License 2.0"
library_name:
  - pytorch
frameworks:
  - pytorch
domain:
  - cv
downloads: 320
stars: 2
tags:
  - "特征提取"
  - "扩散模型"
---

# cv_stable-diffusion-v2_image-feature

> cv_stable-diffusion-v2_image-feature - damo 在 ModelScope 开源的模型。基于扩散模型的图像特征抽取，可用于做特征点匹配。

damo/cv_stable-diffusion-v2_image-feature 是 ModelScope 魔搭社区上的机器学习模型，采用 Apache License 2.0 许可。

- **Repository**: damo/cv_stable-diffusion-v2_image-feature
- **License**: Apache License 2.0
- **Tags**: 特征提取, 扩散模型
- **Downloads**: 320
- **Stars**: 2
- **Last updated**: 2023-11-17

Source: https://www.modelscope.cn/models/damo/cv_stable-diffusion-v2_image-feature

---

## 功能概述

基于扩散模型的图像特征抽取，可用于做特征点匹配。

![video](./assets/teaser.gif)

[Project Page](https://diffusionfeatures.github.io/) | [Paper](https://arxiv.org/abs/2306.03881) | [Colab Demo](https://colab.research.google.com/drive/1tUTJ3UJxbqnfvUMvYH5lxcqt0UdUjdq6?usp=sharing)

## 环境准备
安装独立repo库
```
pip install git+https://github.com/junjiehe96/modelscope_dift.git
```

## 运行代码
```python
from modelscope.pipelines import pipeline
from modelscope.outputs import OutputKeys
from modelscope_dift import ms_wrapper

model = 'damo/cv_stable-diffusion-v2_image-feature'
pipe = pipeline('feature_extraction', model=model, device='gpu', auto_collate=False, model_revision='v1.0.2')
out1 = pipe('https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/face_recognition_1.png', img_size=0,
            t=261, up_ft_index=1, prompt='a photo of a girl', ensemble_size=4, seed=0)[OutputKeys.OUTPUT]  # 1*C*H*W
print(out1)
```

## 参数说明
+ `img_size`: 在输入扩散模型之前调整图像的宽度和高度。 如果设置为 0，则不会执行调整大小操作，因此它将坚持原始图像大小。 默认设置为 [768, 768]。 如果遇到内存问题，您可以减少此值。
+ `t`: 扩散的时间步长，范围[0, 1000]中选择，必须是整数。 对于语义对应，默认 t=261。
+ `up_ft_index`: 用于提取特征图的 U-Net 上采样块的索引，从 [0, 1, 2, 3] 中选择。 up_ft_index=1 默认情况下语义对应。
+ `prompt`: 扩散模型中使用的提示。
+ `ensemble_size`: 每批中用于获取特征的重复图像的数量。 默认情况下 ensemble_size=8。 如果遇到内存问题，您可以减小该值。
+ `seed`: 随机种子，默认为None

## 引用
如果你觉得这个模型对你有所帮助，请考虑引用下面的相关论文：
```BibTeX
@article{tang2023emergent,
  title={Emergent Correspondence from Image Diffusion},
  author={Tang, Luming and Jia, Menglin and Wang, Qianqian and Phoo, Cheng Perng and Hariharan, Bharath},
  journal={arXiv preprint arXiv:2306.03881},
  year={2023}
}
```

## Clone with HTTP
```bash
 git clone https://www.modelscope.cn/damo/cv_stable-diffusion-v2_image-feature.git
```
