ref : https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/notebooks/qwen2.5-vl/qwen2.5-vl.ipynb

model_dir="/xxx/Qwen/Qwen2.5-VL-3B-Instruct"
out_dir="/xxx/OpenVINO/Qwen2.5-VL-3B-Instruct-ov-int4"
optimum-cli export openvino --model ${model_dir} ${out_dir} --weight-format int4  --task image-text-to-text

--task 参数

任务类型简要解析:


1. Zero-shot-object-detection - 零样本目标检测:在没有针对特定对象训练的情况下,识别图像中的对象。
2. Reinforcement-learning - 强化学习:通过与环境互动学习策略的机器学习方法。
3. Video-text-to-text - 视频文本到文本:从视频和相关联的文本中生成描述或回答问题的任务。
4. Feature-extraction - 特征提取:从原始数据中提取有意义的信息或特征,用于进一步处理。
5. Fill-mask - 填充掩码:预测句子中被掩码标记遮蔽的词语。
6. Zero-shot-image-classification - 零样本图像分类:无需专门训练即可对新类别的图像进行分类。
7. Image-text-to-text - 图像文本到文本:结合图像和文本输入生成新的文本输出。
8. Image-classification - 图像分类:确定图像属于哪个类别。
9. Multiple-choice - 多选题回答:从多个选项中选择正确答案的问题回答任务。
10. Depth-estimation - 深度估计:估计场景中物体距离相机的距离。
11. Image-to-image - 图像到图像:将一种类型的图像转换为另一种类型(如风格转移)。
12. Text-to-audio - 文本转音频:将文字信息转化为语音。
13. Visual-question-answering - 视觉问答:根据给定的图像回答自然语言问题。
14. Semantic-segmentation - 语义分割:将图像中的每个像素分配给一个类别标签。
15. Text-generation - 文本生成:自动生成类似人类撰写的文本内容。
16. Text-classification - 文本分类:对文本内容进行分类。
17. Automatic-speech-recognition - 自动语音识别:将口语转换成文本。
18. Object-detection - 目标检测:识别并定位图像中的所有对象。
19. Audio-classification - 音频分类:对音频片段进行分类。
20. Masked-im - 掩码图像建模:类似于填空任务,但应用于图像领域。
21. Image-segmentation - 图像分割:将图像划分为多个部分或区域。
22. Image-to-text - 图像到文本:从图像中生成描述性文本。
23. Token-classification - 标记分类:对文本中的每个单词或标记进行分类(如命名实体识别)。
24. Question-answering - 问答系统:根据给定的上下文回答问题。
25. Mask-generation - 掩码生成:创建用于其他任务(如填空)的掩码。
26. Audio-frame-classification - 音频帧分类:对音频信号的每一帧进行分类。
27. Audio-xvector - 音频x向量:一种用于说话人识别的技术。
28. Sentence-similarity - 句子相似度:衡量两个句子之间的相似程度。
29. Text2text-generation - 文本到文本生成:基于输入文本生成相应的输出文本。


example::

from PIL import Image
from transformers import AutoProcessor, AutoTokenizer
from qwen_vl_utils import process_vision_info
from transformers import TextStreamer

model_dir = "/path/to/model"

min_pixels = 256 * 28 * 28
max_pixels = 1280 * 28 * 28

processor = AutoProcessor.from_pretrained(model_dir , min_pixels=min_pixels, max_pixels=max_pixels)

if processor.chat_template is None:
    tok = AutoTokenizer.from_pretrained(model_dir)
    processor.chat_template = tok.chat_template

example_image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
example_image_path = Path("demo.jpeg")

if not example_image_path.exists():
    Image.open(requests.get(example_image_url, stream=True).raw).save(example_image_path)

image = Image.open(example_image_path)
question = "Describe this image."

messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": f"file://{example_image_path}",
            },
            {"type": "text", "text": question},
        ],
    }
]

# Preparation for inference
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
    text=[text],
    images=image_inputs,
    videos=video_inputs,
    padding=True,
    return_tensors="pt",
)

display(image)
print("Question:")
print(question)
print("Answer:")

generated_ids = model.generate(**inputs, max_new_tokens=100, streamer=TextStreamer(processor.tokenizer, skip_prompt=True, skip_special_tokens=True))

Downloads last month
1
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support