网站怎么免费做推广方案,山东建设厅官方网站,建设网站ppt,wordpress评论邮件通知2024年8月29日#xff0c;阿里发布了 Qwen2-VL#xff01;Qwen2-VL 是基于 Qwen2 的最新视觉语言大模型。与 Qwen-VL 相比#xff0c;Qwen2-VL 具有以下能力#xff1a;
SoTA对各种分辨率和比例的图像的理解#xff1a;Qwen2-VL在视觉理解基准上达到了最先进的性能#… 2024年8月29日阿里发布了 Qwen2-VLQwen2-VL 是基于 Qwen2 的最新视觉语言大模型。与 Qwen-VL 相比Qwen2-VL 具有以下能力
SoTA对各种分辨率和比例的图像的理解Qwen2-VL在视觉理解基准上达到了最先进的性能包括MathVista、DocVQA、RealWorldQA、MTVQA等。理解 20 分钟 的视频Qwen2-VL 可以理解 20 分钟以上的视频以进行高质量的基于视频的问答、对话、内容创建等。可以操作您的手机、机器人等的代理Qwen2-VL 具有复杂的推理和决策能力可以与手机、机器人等设备集成根据视觉环境和文本指令进行自动操作。多语言支持为了服务全球用户除了英文和中文外Qwen2-VL 现在还支持理解图像中不同语言的文本包括大多数欧洲语言、日语、韩语、阿拉伯语、越南语等。 Qwen2-VL-2B 和 Qwen2-VL-7B模型开源了 Qwen2-VL-72B只开源了API开源模型已集成到 Hugging Face Transformers、vLLM 和其他第三方框架中。 一、性能
72B 从六个关键维度评估模型的视觉能力复杂的大学水平问题解决、数学能力、文档和表格理解、多语言文本图像理解、一般场景问答、视频理解和基于代理的交互。总体而言 72B 模型在大多数指标上都展示了顶级性能甚至超过了 GPT-4o 和 Claude 3.5-Sonnet 等闭源模型。值得注意的是它在文档理解方面表现出显着优势。 7B 在 7B 模型上保留了对图像、多图像和视频输入的支持以更具成本效益的模型大小提供有竞争力的性能。具体来说在 DocVQA 等文档理解任务和图像中的多语言文本理解方面表现出色。 2B 此外更小的 2B 模型针对潜在的移动部署进行了优化。尽管体积小巧但该模型在图像、视频和多语言理解方面拥有强大的性能。与其他类似规模的模型相比它在与视频相关的任务、文档理解和一般场景问答方面尤其突出。 二、模型任务表现
2.1 增强的识别功能 Qwen2-VL 现在拥有改进的对象识别功能超越了植物和地标可以理解场景中多个对象之间的复杂关系。我们还显著提高了该模型识别图像中的手写文本和多种语言的能力使其更易于全球用户访问。
示例多对象识别
UserOutput the color and number of each box.
输出每个框的颜色和编号。 Qwen2-VL
The image shows a stack of colorful blocks with numbers on them. Here is the color and number of each block from top to bottom: 该图像显示了一堆带有数字的彩色块。以下是每个块的颜色和编号从上到下 Top row (single block): Blue with the number 9 顶行单个块带有数字 9 的蓝色 Second row (two blocks): Light blue with the number 7, and green with the number 8 第二行两个块浅蓝色的数字 7 和绿色的数字 8 Third row (three blocks): Purple with the number 4, pink with the number 5, and light green with the number 6 第三行三个块紫色的数字 4、粉红色的数字 5 和浅绿色的数字 6 Bottom row (four blocks): Red with the number 0, orange with the number 1, yellow with the number 2, and light green with the number 3 底行四个块红色的数字 0、橙色的数字 1、黄色的数字 2 和浅绿色的数字 3
2.2 视觉推理解决现实世界的问题 在这次迭代中显著提高了 Qwen2-VL 的数学和编码能力。该模型不仅能够通过分析图片来解决问题还可以通过图表分析来解释和解决复杂的数学问题。极度纵横比失真的图像也可以被正确解释。此外还增强了模型从真实世界图像和图表中提取信息的能力并提高了其指令跟踪技能。这种视觉感知和逻辑推理的融合使模型能够解决实际问题弥合抽象概念和有形解决方案之间的差距。
示例数学
User 用户
Find the length of AC in the isosceles triangle ABC. 求等腰三角形 ABC 中 AC 的长度。 Qwen2-VL
Since triangle ABC is isosceles, we know that AC BC. Therefore, we can set the expressions for AC and BC equal to each other and solve for x: 由于三角形 ABC 是等腰三角形我们知道 AC BC。因此我们可以将 AC 和 BC 的表达式设置为彼此相等并求解 x
4x 1 5x - 0.5
Subtracting 4x from both sides, we get: 从两侧减去 4 倍我们得到
1 x - 0.5
Adding 0.5 to both sides, we get: 将 0.5 加到两侧我们得到
1.5 x
Now that we know the value of x, we can substitute it back into the expression for AC to find its length: 现在我们知道了 x 的值我们可以将其代入表达式中让 AC 找到它的长度
AC 4x 1
AC 4(1.5) 1
AC 6 1
Therefore, the length of AC is 7. 因此AC 的长度为 7。
2.3 视频理解和实时聊天 除了静态图像之外Qwen2-VL 还将其能力扩展到视频内容分析。它可以总结视频内容回答与之相关的问题并实时保持持续的对话流提供实时聊天支持。此功能允许它充当个人助理通过提供直接从视频内容中提取的见解和信息来帮助用户。
UserPlease describe the video in detail. 请详细描述视频。
Qwen2-VL
The video begins with a man speaking to the camera, followed by a group of people sitting in a control room. The camera then cuts to two men floating inside a space station, where they are seen speaking to the camera. The men appear to be astronauts, and they are wearing space suits. The space station is filled with various equipment and machinery, and the camera pans around to show the different areas of the station. The men continue to speak to the camera, and they appear to be discussing their mission and the various tasks they are performing. Overall, the video provides a fascinating glimpse into the world of space exploration and the daily lives of astronauts. 视频开始时一名男子对着镜头讲话然后是一群坐在控制室里的人。然后镜头切换到漂浮在空间站内的两名男子可以看到他们对着镜头说话。这些人似乎是宇航员他们穿着宇航服。空间站里装满了各种设备和机械摄像机四处平移以显示空间站的不同区域。这些人继续对着镜头说话他们似乎在讨论他们的任务和他们正在执行的各种任务。总体而言该视频提供了对太空探索世界和宇航员日常生活的迷人一瞥。
User 用户
What is the color of the clothes the two astronauts wearing? 两位宇航员穿的衣服是什么颜色的
Qwen2-VL
The two astronauts are wearing blue and black clothes. 这两名宇航员穿着蓝色和黑色的衣服。
2.4 可视化代理功能函数调用和可视化交互 Qwen2-VL 作为视觉代理表现出强大的潜力可促进类似于人类对世界感知的交互。 该模型可以函数调用使其能够利用外部工具通过破译视觉线索来实时检索数据无论是航班状态、天气预报还是包裹跟踪。这种视觉解释与功能执行的集成提升了它的实用性使其成为信息管理和决策的强大工具。
示例函数调用
Ask about the weather 询问天气 Visual Interactions represent a significant stride towards mimicking human perception. By allowing the model to engage with visual stimuli akin to human senses, we’re pushing the boundaries of AI’s ability to perceive and respond to its environment. This capability paves the way for more intuitive and immersive interactions, where Qwen2-VL acts not just as an observer, but an active participant in our visual experiences. 视觉交互代表了向模仿人类感知迈出的重大一步。通过允许模型与类似于人类感官的视觉刺激互动我们正在突破 AI 感知和响应环境的能力的界限。此功能为更直观和身临其境的交互铺平了道路Qwen2-VL 不仅充当观察者而且是我们视觉体验的积极参与者。
三、模型架构 总体而言继续使用 Qwen-VL 架构该架构利用了 Vision Transformer ViT 模型和 Qwen2 语言模型。对于所有这些变体使用了具有大约 600M 参数的 ViT旨在无缝处理图像和视频输入。为了进一步增强模型有效感知和理解视频中视觉信息的能力引入了几项关键升级
Qwen2-VL 中的一项关键架构改进是实现了 Naive Dynamic Resolution 支持。与前代产品不同Qwen2-VL 可以处理任意图像分辨率将它们映射到动态数量的视觉标记从而确保模型输入与图像中固有信息之间的一致性。这种方法更接近于人类视觉感知使模型能够处理任何清晰度或大小的图像。 另一个关键的架构增强功能是多模态旋转位置嵌入 M-ROPE 的创新。通过将原始旋转嵌入物解构为代表时间和空间高度和宽度信息的三个部分M-ROPE 使 LLM 能够同时捕获和整合 1D 文本、2D 视觉和 3D 视频位置信息。 四、使用 Qwen2-VL 进行开发 要使用最大的 Qwen2-VL 模型 Qwen2-VL-72B您可以通过我们的官方 API注册账号并通过 DashScope 获取 API 密钥临时访问它如下所示
from openai import OpenAIimport osimport base64def encode_image(image_path): with open(image_path, rb) as image_file: return base64.b64encode(image_file.read()).decode(utf-8)# Path to your imageimage_path dog_and_girl.jpeg# Getting the base64 stringbase64_image encode_image(image_path)def get_response(): client OpenAI( api_keyos.getenv(DASHSCOPE_API_KEY), base_urlhttps://dashscope.aliyuncs.com/compatible-mode/v1, ) completion client.chat.completions.create( modelqwen-vl-max-0809, messages[ { role: user, content: [ {type: text, text: What is this?}, { type: image_url, image_url: { url: https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg }, }, { type: image_url, image_url: {url: fdata:image/jpeg;base64,{base64_image}}, }, ], } ], top_p0.8, streamTrue, stream_options{include_usage: True}, ) for chunk in completion: print(chunk.model_dump_json())if __name__ __main__: get_response() Qwen2-VL 系列的 2B 和 7B 型号是开源的可在 Hugging Face 和 ModelScope 上访问。 确保你从源安装transformers pip install githttps://github.com/huggingface/transformers 因为Qwen2-VL 的代码刚刚合并到 main 分支中。如果您未从源码安装它则可能会遇到以下错误
KeyError: qwen2_vl 阿里提供了一个工具包来帮助您更方便地处理各种类型的视觉输入。它支持的输入包括 base64、URL 以及交错图像和视频。您可以使用以下命令安装它
pip install qwen-vl-utils 下面是一个用于演示的代码片段。具体来说我们建议尽可能使用 flash attention 2以便加速和节省内存。
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessorfrom qwen_vl_utils import process_vision_info# default: Load the model on the available device(s)model Qwen2VLForConditionalGeneration.from_pretrained( Qwen/Qwen2-VL-7B-Instruct, device_mapauto)# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.# model Qwen2VLForConditionalGeneration.from_pretrained(# Qwen/Qwen2-VL-7B-Instruct,# torch_dtypetorch.bfloat16,# attn_implementationflash_attention_2,# device_mapauto,# )# default processerprocessor AutoProcessor.from_pretrained(Qwen/Qwen2-VL-7B-Instruct)# The default range for the number of visual tokens per image in the model is 4-16384. You can set min_pixels and max_pixels according to your needs, such as a token count range of 256-1280, to balance speed and memory usage.# min_pixels 256*28*28# max_pixels 1280*28*28# processor AutoProcessor.from_pretrained(Qwen/Qwen2-VL-7B-Instruct, min_pixelsmin_pixels, max_pixelsmax_pixels)messages [ { role: user, content: [ { type: image, image: https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg, }, {type: text, text: Describe this image.}, ], }]# Preparation for inferencetext processor.apply_chat_template( messages, tokenizeFalse, add_generation_promptTrue)image_inputs, video_inputs process_vision_info(messages)inputs processor( text[text], imagesimage_inputs, videosvideo_inputs, paddingTrue, return_tensorspt,)# Inference: Generation of the outputgenerated_ids model.generate(**inputs, max_new_tokens128)generated_ids_trimmed [ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]output_text processor.batch_decode( generated_ids_trimmed, skip_special_tokensTrue, clean_up_tokenization_spacesFalse)print(output_text) Qwen2-VL已经支持开源生态系统中的一系列工具和框架包括量化 AutoGPTQ、AutoAWQ、部署 vLLM、微调 Llama-Factory 等