Module 5

Module 5: CV & Agent 集成

将计算机视觉能力整合到 Agent,构建自动驾驶场景分析系统。

Vision LLMCV Tool自动驾驶场景多模态 RAG

学习目标

将计算机视觉能力整合到 Agent 中,构建自动驾驶场景分析系统。

为什么需要 CV + Agent?

传统 CV 流水线:输入图片 → 模型推理 → 输出结果 → 人工分析。

CV + Agent:输入图片 → Agent 自主调用检测模型 → 综合分析 → 给出自然语言结论。


5.1 视觉 LLM (vision_llm_basics.py)

支持的视觉模型

模型 接入方式 用途
通义千问 VL (qwen-vl-plus) OpenAI 兼容 图片理解、场景描述
智谱 GLM-4V OpenAI 兼容 图片理解、图表分析

图片传入方式


message = HumanMessage(content=[
    {"type": "text", "text": "请描述这张图片"},
    {"type": "image_url", "image_url": {
        "url": "https://example.com/image.jpg"  # 或 base64
    }},
])
response = vl_llm.invoke([message])

5.2 CV 模型作为工具 (ad_scenario_agent.py) ⭐

架构


用户上传图片 → Agent 调用 CV 工具 → 检测结果 → LLM 综合分析 → 场景报告

CV 工具封装


@tool
def detect_objects(image_path: str) -> str:
    """检测图像中的目标(车辆、行人、车道线等)"""
    # 调用 YOLO / PETR / BEVFormer 等模型
    results = model.predict(image_path)
    return format_results(results)

@tool
def analyze_lanes(image_path: str) -> str:
    """分析车道线信息"""
    ...

@tool
def check_weather_lighting(image_path: str) -> str:
    """评估天气和光照条件"""
    ...

自动驾驶场景分析 Prompt


你是一个自动驾驶场景分析系统。请分析:
1. 场景类型(城市/高速/乡村)
2. 检测到的道路使用者
3. 潜在危险情况
4. 建议的驾驶行为

Module 5 核心总结

概念 说明
Vision LLM 直接理解图片内容(qwen-vl-plus / glm-4v)
CV Tool 将 YOLO 等检测模型封装为 Agent 工具
多模态 RAG 用自然语言检索图片,用图片辅助回答
AD 场景分析 检测 + 推理 + 风险评估的完整流水线