Compute action accuracy for motion videos using Gemini API Args: full_info_path: Path to JSON file with video information device: Device to use (not used in this implementation) api_key: Gemini API key (can also be set via GEMINI_API_KEY env var) vlm_fps
(full_info_path: str, device: str,
api_key: Optional[str] = None, **kwargs)
| 23 | |
| 24 | |
| 25 | def compute_motion_generalizability(full_info_path: str, device: str, |
| 26 | api_key: Optional[str] = None, **kwargs) -> Dict[str, Any]: |
| 27 | """ |
| 28 | Compute action accuracy for motion videos using Gemini API |
| 29 | |
| 30 | Args: |
| 31 | full_info_path: Path to JSON file with video information |
| 32 | device: Device to use (not used in this implementation) |
| 33 | api_key: Gemini API key (can also be set via GEMINI_API_KEY env var) |
| 34 | vlm_fps: Target effective fps for VLM sampling (default: 5) |
| 35 | **kwargs: Additional arguments |
| 36 | |
| 37 | Returns: |
| 38 | Dictionary with evaluation results |
| 39 | """ |
| 40 | # Get API key from parameter or environment |
| 41 | if api_key is None: |
| 42 | api_key = os.getenv('GEMINI_API_KEY') |
| 43 | |
| 44 | if not api_key: |
| 45 | raise ValueError("Gemini API key must be provided either as parameter or GEMINI_API_KEY environment variable") |
| 46 | |
| 47 | # Load dimension information using the same pattern as motion_quality.py |
| 48 | prompt_dict_ls = load_dimension_info(full_info_path, dimension='Motion_Generalizability') |
| 49 | |
| 50 | # Base prompt for motion analysis |
| 51 | prompt = """ |
| 52 | You are given a rendered video showing captured human motion, with no background or interacting objects. First, analyze the human motion in the video in detail by describing the person's body posture, limb movements, and any repetitive or distinctive motion patterns you observe. |
| 53 | Then, compare the observed motion with the provided textual description of an expected motion. When evaluating, prioritize the semantic consistency of the action (e.g., whether the core intent and type of movement match) over the visual quality, smoothness, or physical realism of the rendering. Finally, determine whether the observed motion matches the described motion. Respond with a short justification followed by a final answer in "Answer: yes" or "Answer: no". |
| 54 | Example output is: "The person in the video is standing and repeatedly clapping their hands above chest level. The motion in the video matches the given motion description 'clapping'. Answer: yes." |
| 55 | The provided motion description to verify: """ |
| 56 | |
| 57 | gemini_workers = kwargs.get('gemini_workers', 8) |
| 58 | vlm_fps = kwargs.get('vlm_fps', 5) # Default 1fps for VLM sampling |
| 59 | |
| 60 | cnt = 0 |
| 61 | cor_num = 0 |
| 62 | accuracy_list = [] |
| 63 | per_motion_metrics = [] |
| 64 | |
| 65 | def evaluate_entry(prompt_dict): |
| 66 | video_label = prompt_dict.get('prompt', 'unknown') |
| 67 | video_path = prompt_dict.get('evaluation_file', '') |
| 68 | motion_id = prompt_dict.get('id') |
| 69 | |
| 70 | if not os.path.exists(video_path): |
| 71 | return {"skip": True, "id": motion_id, "error": f"Missing video {video_path}"} |
| 72 | |
| 73 | try: |
| 74 | # Read video bytes directly - fps is now handled by Gemini API |
| 75 | with open(video_path, 'rb') as f: |
| 76 | video_bytes = f.read() |
| 77 | except Exception as exc: |
| 78 | return {"skip": True, "id": motion_id, "error": f"Video read error: {exc}"} |
| 79 | |
| 80 | |
| 81 | try: |
| 82 | response = call_gemini_api(video_bytes, prompt + f'"{video_label}".', api_key, fps=vlm_fps) |
nothing calls this directly
no test coverage detected