LongVU :Meta AI 的解锁长视频理解模型,利用自适应时空压缩技术彻底改变视频理解方式

Meta AI在视频理解方面取得了令人瞩目的里程碑式成就,推出了LongVU,这是一种开创性的模型,能够理解以前对人工智能系统来说具有挑战性的长视频。 研究论文 "LongVU:用于长视频语言理解的时空自适应压缩 "提出了一种革命性的方法,使人工智能能够有效地处理和理解长达几分钟甚至一小时的视频,而这在以前是无法实现的。

在这里插入图片描述
多模态大语言模型(MLLM)在理解和分析视频内容方面取得了可喜的进展。 然而,受限于给定的上下文长度,处理长视频仍然是一项重大挑战。 为了解决这一限制,我们提出了一种时空自适应压缩机制 LongVU,以减少视频标记的数量,同时保留长视频的视觉细节。 我们的想法是利用跨模态查询和帧间依赖关系,自适应地减少视频中的时空冗余。 具体来说,我们利用 DINOv2 特征来删除相似度高的冗余帧。 然后,我们利用文本引导的跨模态查询来选择性地减少帧特征。 此外,我们还根据帧与帧之间的时间依赖关系,对帧进行空间标记缩减。 我们的自适应压缩策略在有限的上下文长度内有效地处理了大量帧,几乎没有损失任何视觉信息。 在各种视频理解基准测试中,我们的 LongVU 始终超越现有方法,尤其是在长达一小时的视频理解任务(如 VideoMME 和 MLVU)中。 在轻量级 LLM 的情况下,我们的 LongVU 还能有效地扩展到更小的规模,并具有最先进的视频理解性能。

LongVU 架构

LongVU 的结构。 给定一个密集采样的视频帧,我们首先利用 DINOv2 去除冗余帧,然后融合 SigLIP 和 DINOv2 的剩余帧特征。 然后,我们通过跨模态查询有选择地减少视觉标记。 最后,我们基于时间依赖性进行空间标记压缩,以进一步满足 LLM 的有限上下文长度。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

示例

# git clone https://github.com/Vision-CAIR/LongVU
import numpy as np
import torch
from longvu.builder import load_pretrained_model
from longvu.constants import (DEFAULT_IMAGE_TOKEN,IMAGE_TOKEN_INDEX,
)
from longvu.conversation import conv_templates, SeparatorStyle
from longvu.mm_datautils import (KeywordsStoppingCriteria,process_images,tokenizer_image_token,
)
from decord import cpu, VideoReadertokenizer, model, image_processor, context_len = load_pretrained_model("./checkpoints/longvu_qwen", None, "cambrian_qwen",
)model.eval()
video_path = "./examples/video1.mp4"
qs = "Describe this video in detail"vr = VideoReader(video_path, ctx=cpu(0), num_threads=1)
fps = float(vr.get_avg_fps())
frame_indices = np.array([i for i in range(0, len(vr), round(fps),)])
video = []
for frame_index in frame_indices:img = vr[frame_index].asnumpy()video.append(img)
video = np.stack(video)
image_sizes = [video[0].shape[:2]]
video = process_images(video, image_processor, model.config)
video = [item.unsqueeze(0) for item in video]qs = DEFAULT_IMAGE_TOKEN + "\n" + qs
conv = conv_templates["qwen"].copy()
conv.append_message(conv.roles[0], qs)
conv.append_message(conv.roles[1], None)
prompt = conv.get_prompt()input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(model.device)
stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
keywords = [stop_str]
stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)
with torch.inference_mode():output_ids = model.generate(input_ids,images=video,image_sizes=image_sizes,do_sample=False,temperature=0.2,max_new_tokens=128,use_cache=True,stopping_criteria=[stopping_criteria],)
pred = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()

Github:https://github.com/Vision-CAIR/LongVU

如何 24GB VRAM 运行

https://github.com/Vision-CAIR/LongVU/issues/6

# git clone https://github.com/Vision-CAIR/LongVU
import numpy as np
import torch
from longvu.builder import load_pretrained_model
from longvu.constants import (DEFAULT_IMAGE_TOKEN,IMAGE_TOKEN_INDEX,
)
from longvu.conversation import conv_templates, SeparatorStyle
from longvu.mm_datautils import (KeywordsStoppingCriteria,process_images,tokenizer_image_token,
)
from decord import cpu, VideoReadertokenizer, model, image_processor, context_len = load_pretrained_model("Vision-CAIR/LongVU_Qwen2_7B", model_base=None,model_name="cambrian_qwen",device="cuda:0"
)model.eval()
video_path = "./examples/video1.mp4"
qs = "Describe this video in detail"vr = VideoReader(video_path, ctx=cpu(0), num_threads=1)
fps = float(vr.get_avg_fps())
# frame_indices = np.array([i for i in range(0, len(vr), round(fps),)])
num_frames = 1000 if len(vr) > 1000 else len(vr)
frame_indices = np.array([i for i in range(0, num_frames, round(fps),)])video = []
for frame_index in frame_indices:img = vr[frame_index].asnumpy()video.append(img)
video = np.stack(video)
image_sizes = [video[0].shape[:2]]
video = process_images(video, image_processor, model.config)
video = [item.unsqueeze(0) for item in video]qs = DEFAULT_IMAGE_TOKEN + "\n" + qs
conv = conv_templates["qwen"].copy()
conv.append_message(conv.roles[0], qs)
conv.append_message(conv.roles[1], None)
prompt = conv.get_prompt()input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(model.device)
stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
keywords = [stop_str]
stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)
# with torch.inference_mode():
#     output_ids = model.generate(
#         input_ids,
#         images=video,
#         image_sizes=image_sizes,
#         do_sample=False,
#         temperature=0.2,
#         max_new_tokens=128,
#         use_cache=True,
#         stopping_criteria=[stopping_criteria],
#     )
attention_mask = torch.ones_like(input_ids)
with torch.inference_mode():output_ids = model.generate(input_ids,attention_mask=attention_mask,images=video,image_sizes=image_sizes,do_sample=True,temperature=0.2,pad_token_id=tokenizer.eos_token_id,max_new_tokens=512,use_cache=True,stopping_criteria=[stopping_criteria],)
pred = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()

输出:

‘The video begins with a scene featuring two characters in an animated setting, one dressed in a bright yellow and red outfit with a mask, and the other in a blue and white traditional robe, standing on a rocky terrain with a green, leaf-like structure and a mountainous backdrop. The character in the yellow and red outfit is seen making a gesture with their right hand, while the other character appears to be speaking or reacting to the first character. The scene then transitions to a misty, ethereal environment where the same two characters are now standing on a staircase leading to a building with a golden roof, surrounded by smoke or clouds. The character in the yellow and red outfit is now holding a sword, while the other character is holding a fan, and both are looking up at the building. The scene shifts again to a large, ornate building with a golden roof, where a figure in a white and red outfit is seen descending a staircase, with smaller figures in white and red attire standing on the steps, and a large, white, cloud-like object in the foreground. The final scene shows the same building with the figure in white and red now seated on a golden throne, surrounded by smaller figures in white and red, and a large, white, cloud-like object still in the foreground, suggesting a ceremonial or significant event taking place.’

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/59624.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

二分答案—愤怒的牛-P1676 [USACO05FEB] Aggressive cows G

[USACO05FEB] Aggressive cows G 题目描述 农夫约翰建造了一座有 n n n 间牛舍的小屋,牛舍排在一条直线上,第 i i i 间牛舍在 x i x_i xi​ 的位置,但是约翰的 m m m 头牛对小屋很不满意,因此经常互相攻击。约翰为了防止牛之…

什么是兼容性测试

兼容性测试,提供具有兼容性特性的云端设备(覆盖主流品牌、SDK、分辨率),通过模拟用户行为进行真机测试。及时有效的发现应用中存在的兼容性问题。解除测试人员的双手,提高测试效率,保证产品在海量真机上的高…

IDEA:ctrl+/ 快捷键生成的注释,设置“//”开始位置

问题场景: IDEA中使用 ctrl/ 快捷键,//显示在最左边(顶格),不美观,中间隔了好长的空格,如图: 解决方法: 操作步骤 File–>Sttings–>Editor–>Code Style–>Java–>…

中文文章进行加密编码及解码的方法python实现

愿我们终有重逢之时,而你还记得我们曾经讨论的话题。 group 868373192 second group 277356808 在Python中,可以使用多种方法对中文文章进行加密编码及解码。以下是几种常见的方法: 1. 使用Base64编码 Base64是一种基于64个可打印字符来表示二进制数据的编码方式。它可以…

掌握springboot过滤器,拦截器 ,aop

前言: Spring Boot 中的过滤器(Filter)、拦截器(Interceptor)和 AOP(面向切面编程)都是处理请求的常用技术,但它们在处理请求的时机、范围和方式上有所不同。下面详解分别介绍&#…

XLA中生成Causal Mask上三角-inf矩阵

transformers生成CausalAttentionMask的上三角-inf矩阵: 参考transformers源码 import torch import torch_xla import torch_xla.core.xla_model as xm import osos.environ[PJRT_DEVICE]IPU # os.environ[PJRT_DEVICE]GPU # os.environ[XLA_FLAGS]--xla_dump_tog…

IDEA2024下安装kubernetes插件并配置进行使用

【1】安装插件 其实2024.2.3下默认已经安装了kubernetes插件,如果你发现自己IDEA中没有,在市场里面检索并下载即可。 【2】kubernetes配置 ① 前置工作 首先你要准备一个config文件和一个kubectl.exe 。 config文件类似如下: apiVersi…

H7-TOOL的CAN/CANFD助手增加帧发送成功标识支持, 继续加强完善功能细节

2.27版本固件正式携带此功能,包括之前做的负载率检测和错误信息展示也将集成到这个版本固件中。 对于接收,我们可以直接看到效果,而发送不行,所以打算在发送的地方展示下发送成功标识。CAN发送不像串口,需要等待应答后…

微调LLM时,full、freeze、lora区别

LLama-Factory支持full、freeze、lora三种微调,区别: Full微调:Full微调是指在微调过程中更新整个模型的所有参数。这意味着所有的层和参数都会被更新,并且在微调期间都会参与训练。Full微调通常用于对模型进行全面的调整&#xf…

CSP/信奥赛C++刷题训练:经典广搜例题(4):洛谷P1746 :离开中山路

CSP/信奥赛C刷题训练:经典广搜例题(4):洛谷P1746 :离开中山路 题目背景 《爱与愁的故事第三弹shopping》最终章。 题目描述 爱与愁大神买完东西后,打算坐车离开中山路。现在爱与愁大神在 x 1 , y 1 x_1…

CST汽车天线仿真(双向混合求解)

CST从2018版本开始具有双向混合求解,到2019版已经通用微波工作室的各个求解器之间的双向混合。具体的混合对象如下图: 对天线的安装和耦合仿真,意味着对复杂结构(天线)和电大尺寸环境(安装平台,…

booleader的工作原理

Bootloader 的工作原理 在嵌入式系统中,Bootloader 是系统上电或复位时执行的第一个程序,它负责将嵌入式系统的主程序(通常是操作系统或用户应用程序)加载到内存中并启动运行。Bootloader 是嵌入式系统中的一个关键组件&#xff…

【鸿蒙】HarmonyOS NEXT应用开发快速入门教程之布局篇(下)

系列文章目录 【鸿蒙】HarmonyOS NEXT开发快速入门教程之ArkTS语法装饰器(上) 【鸿蒙】HarmonyOS NEXT开发快速入门教程之ArkTS语法装饰器(下) 【鸿蒙】HarmonyOS NEXT应用开发快速入门教程之布局篇(上) 【…

[Code]U-Mamba

U-MambaEnc-2d.py # 导入必要的模块 import torch import torch.nn as nn import torch.nn.functional as F# 定义一个上采样层类,继承自 nn.Module class UpsampleLayer(nn.Module):# 初始化方法,定义层的结构和所需的超参数def __init__(self, …

RAG框架(Retrieval-Augmented Generation)和BM25

目录 RAG框架(Retrieval-Augmented Generation)和BM25 一、RAG框架概述 二、BM25算法概述 三、RAG框架与BM25的关系 四、举例说明 RAG框架(Retrieval-Augmented Generation)和BM25 RAG框架(Retrieval-Augmented Generation)和BM25之间存在密切的关系,尤其是在信息…

【HCIP园区网综合拓扑实验】配置步骤与详解(未施工完,持续更新中)

一、实验要求 实验拓扑图如上图所示 1、按照图示的VLAN及IP地址需求,完成相关配置 2、要求SW1为VLAN 2/3的主根及主网关 SW2为vlan 20/30的主根及主网关 SW1和SW2互为备份 3、可以使用super vlan 4、上层通过静态路由协议完成数据通信过程 5、…

css-flex布局属性

flex 布局的优势 flex 布局的子元素不会脱离文档流flex 是一种现代的布局方式,是 W3C 第一次提供真正用于布局的 CSS 规范 弹性盒子、子元素 弹性盒子:指的是使用 display:flex 或 display:inline-flex 声明的父容器 声明:使用 display:fl…

C++设计模式结构型模式———外观模式

文章目录 一、引言二、外观模式三、总结 一、引言 外观模式是一种结构型设计模式, 能为程序库、 框架或其他复杂类提供一个简单的接口。也就是说,该模式的目的用于隔离接口,换句话说,就是扮演中间层的角色,把本来结合…

软件设计师:排序算法总结

一、直接插入 排序方式:从第一个数开始,拿两个数比较,把后面一位跟前面的数比较,把较小的数放在前面一位 二、希尔 排序方式:按“增量序列(步长)”分组比较,组内元素比较交换 假设…

Tips:如何选择最佳邮件群发工具?

在数字营销的世界中,电子邮件仍然是与客户沟通的最有效方式之一。无论是推广新产品、发送新闻简报,还是进行客户关系管理,邮件群发工具都扮演着至关重要的角色。然而,市场上有如此多的选择,如何才能找到最适合您业务需…