File size: 1,810 Bytes
3f86d6a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | """
示例:如何使用视频输入到Qwen2.5-VL模型
"""
from model_llm import PersonalityAnalyzer
from config import Config
# 配置使用Qwen2.5-VL-8B(如果可用)
# Config.MODEL_NAME = "Qwen/Qwen2-VL-8B-Instruct"
# 初始化模型
print("初始化模型...")
analyzer = PersonalityAnalyzer()
# 示例1: 直接使用视频路径(推荐)
video_path = "../First-Impression/data/first-impressions-v2/train/example.mp4"
result = analyzer.predict(
video_path=video_path,
text="这是视频的转录文本...", # 可选
max_frames=20, # 15秒视频用20帧
frame_selection="smart" # 智能选择重要帧
)
print("\n预测结果:")
for trait, score in result["scores"].items():
print(f" {trait}: {score:.3f}")
# 示例2: 使用图像路径列表(如果已提取帧)
image_paths = [
"ImageData/trainingData/video1/frame_001.jpg",
"ImageData/trainingData/video1/frame_002.jpg",
# ... 更多帧
]
result2 = analyzer.predict(
images=image_paths,
text="转录文本...",
max_frames=20 # 限制最多20帧
)
# 示例3: 多模态输入(视频+文本+音频描述)
result3 = analyzer.predict(
video_path=video_path,
text="完整的转录文本内容...",
audio_description="音频特征:语速中等,音调平稳...",
max_frames=20,
frame_selection="uniform" # 均匀采样
)
print("\n多模态预测结果:")
for trait, score in result3["scores"].items():
print(f" {trait}: {score:.3f}")
# 示例4: 长视频处理(自动调整帧数)
long_video = "long_video.mp4" # 假设是3分钟的视频
result4 = analyzer.predict(
video_path=long_video,
max_frames=50, # 长视频用更多帧
frame_selection="smart"
)
print(f"\n长视频处理: 提取了 {len(result4.get('frames_used', []))} 帧")
|