Welcome to RDK S600 Developer Kit repository
4. Multimodal visual understanding voice interaction
4. Multimodal Visual Understanding Voice Interaction
4. Multimodal Visual Understanding Voice Interaction1. Concept Introduction1.1 What is "Visual Understanding"?1.2 Brief Description of Implementation Principles2. Code AnalysisKey Code1. Tool Layer Entry (largemodel/utils/tools_manager.py)2. Model Interface Layer (largemodel/utils/large_model_interface.py)Code Analysis3.1 Configuring Offline Large Model3.1.1 Configuring LLM Platform (yahboom.yaml)3.1.2 Configuring Model Interface (large_model_interface.yaml)3.2 Startup and Testing4. Common Issues and Solutions4.1 Very Slow Response
1. Concept Introduction
1.1 What is "Visual Understanding"?
In the largemodel project, the Multimodal Visual Understanding feature enables the robot to not just "see" a pixel matrix, but to truly "understand" the content, objects, scenes, and relationships within an image. This is like giving the robot a pair of thinking eyes.
The core tool of this function is seewhat. When a user issues a command like "see what's here", the system invokes this tool, triggering a series of background operations, and ultimately feeds back the AI's analysis of the real-time scene to the user in natural language.
1.2 Brief Description of Implementation Principles
The basic principle is to input two different types of information -- images (visual information) and text (linguistic information) -- into a powerful multimodal large model (such as LLaVA).
- Image Encoding: The model first converts the input image into digital vectors that the computer can understand through a Vision Encoder. These vectors capture the color, shape, texture, and other features of the image.
- Text Encoding: At the same time, the user's question (such as "what's on the table?") is also converted into text vectors.
- Cross-modal Fusion: The most critical step -- the model fuses the image vectors and text vectors in a special "Attention Layer". The model learns to "attend" to the parts of the image relevant to the question. For example, when asking about the "table", the model will focus more on regions in the image that match "table" features.
- Answer Generation: Finally, a Large Language Model (LLM) component generates descriptive text as an answer based on the fused information.
Simply put, it uses text to "highlight" the corresponding parts in the image, then uses language to describe the "highlighted" parts.
2. Code Analysis
Key Code
1. Tool Layer Entry (largemodel/utils/tools_manager.py)
The seewhat function in this file defines the execution flow of the tool.
x# From largemodel/utils/tools_manager.pyclass ToolsManager: # ... def seewhat(self): """ Capture camera frame and analyze environment with AI model. """ self.node.get_logger().info("Executing seewhat() tool") image_path = self.capture_frame() if image_path: # Use isolated context for image analysis. analysis_text = self._get_actual_scene_description(image_path) # Return structured data for the tool chain. return { "description": analysis_text, "image_path": image_path } else: # ... (Error handling) return None def _get_actual_scene_description(self, image_path, message_context=None): """ Get AI-generated scene description for captured image. """ try: # ... (Build Prompt) # Force use of a plain text system prompt with a clean, one-time context. simple_context = [{ "role": "system", "content": "You are an image description assistant. ..." }] result = self.node.model_client.infer_with_image(image_path, scene_prompt, message=simple_context) # ... (Process result) return description except Exception as e: # ...2. Model Interface Layer (largemodel/utils/large_model_interface.py)
The infer_with_image function in this file is the unified entry point for all image understanding tasks, responsible for calling the specific model implementation based on configuration.
xxxxxxxxxx# From largemodel/utils/large_model_interface.pyclass model_interface: # ... def infer_with_image(self, image_path, text=None, message=None): """Unified image inference interface.""" # ... (Prepare messages) try: # Based on the value of self.llm_platform, determine which specific implementation to call if self.llm_platform == 'ollama': response_content = self.ollama_infer(self.messages, image_path=image_path) elif self.llm_platform == 'tongyi': # ... Tongyi model logic pass # ... (Other platform logic) # ... return {'response': response_content, 'messages': self.messages.copy()}Code Analysis
The implementation of this function involves two main layers: the tool layer defines business logic, and the model interface layer handles communication with the large language model. This layered design is key to achieving platform versatility.
Tool Layer (
tools_manager.py):- The
seewhatfunction is the business core of the visual understanding feature. It encapsulates the complete workflow of the "look" action: first calling thecapture_framemethod to obtain an image, then calling_get_actual_scene_descriptionto prepare a prompt for requesting the model to analyze the image. - The most critical step is calling the model interface layer's
infer_with_imagemethod. It doesn't care which model is used underneath; it only needs to pass the two core pieces of data: "image" and "analysis instruction". - Finally, it packa
- The