Showing
6 changed files
with
17 additions
and
16 deletions
| @@ -16,6 +16,7 @@ class FootballReplayMatch: | @@ -16,6 +16,7 @@ class FootballReplayMatch: | ||
| 16 | model_name = value_or_default(settings.llm.model_name, None) | 16 | model_name = value_or_default(settings.llm.model_name, None) |
| 17 | temperature = value_or_default(settings.llm.temperature, 0.7) | 17 | temperature = value_or_default(settings.llm.temperature, 0.7) |
| 18 | self.cache_dir = value_or_default(settings.common.cache_dir, None) | 18 | self.cache_dir = value_or_default(settings.common.cache_dir, None) |
| 19 | + self.task_log_dir = value_or_default(settings.common.task_log_dir, None) | ||
| 19 | save_frames_enable = value_or_default(settings.save_frames_enable, False) | 20 | save_frames_enable = value_or_default(settings.save_frames_enable, False) |
| 20 | 21 | ||
| 21 | self.videoEventRecognition = FootballReplayVideoEvent(llm_base_url, model_name, temperature, 'no_key', self.cache_dir, save_frames_enable) | 22 | self.videoEventRecognition = FootballReplayVideoEvent(llm_base_url, model_name, temperature, 'no_key', self.cache_dir, save_frames_enable) |
| @@ -39,11 +40,11 @@ class FootballReplayMatch: | @@ -39,11 +40,11 @@ class FootballReplayMatch: | ||
| 39 | return None | 40 | return None |
| 40 | 41 | ||
| 41 | def det_goal_replay(self, replay, task_id): | 42 | def det_goal_replay(self, replay, task_id): |
| 42 | - return self.videoEventRecognition.video_event(replay, cache_dir=os.path.join(self.cache_dir, task_id, "replay")) | 43 | + return self.videoEventRecognition.video_event(replay, cache_dir=os.path.join(self.cache_dir, "replays"), task_log_dir=os.path.join(self.task_log_dir, task_id)) |
| 43 | 44 | ||
| 44 | 45 | ||
| 45 | def match_by_llm(self, replay, events, task_id): | 46 | def match_by_llm(self, replay, events, task_id): |
| 46 | - return self.videoMatchLive.match_batch(replay, events, max_parallel=2, cache_dir=os.path.join(self.cache_dir, task_id, "envents")) | 47 | + return self.videoMatchLive.match_batch(replay, events, max_parallel=2, cache_dir=os.path.join(self.cache_dir, "events"), task_log_dir=os.path.join(self.task_log_dir, task_id)) |
| 47 | 48 | ||
| 48 | def replay_match_event(self, data): | 49 | def replay_match_event(self, data): |
| 49 | """ | 50 | """ |
| @@ -25,7 +25,7 @@ def _fake_settings(match_by_time_threshold: int = 30): | @@ -25,7 +25,7 @@ def _fake_settings(match_by_time_threshold: int = 30): | ||
| 25 | return SimpleNamespace( | 25 | return SimpleNamespace( |
| 26 | match_by_time_threshold=match_by_time_threshold, | 26 | match_by_time_threshold=match_by_time_threshold, |
| 27 | llm=SimpleNamespace(base_url="http://192.168.1.59:11434/v1", model_name="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7), | 27 | llm=SimpleNamespace(base_url="http://192.168.1.59:11434/v1", model_name="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7), |
| 28 | - common=SimpleNamespace(cache_dir="/root/lzw/tmp_0518_replay_cache0521_01"), | 28 | + common=SimpleNamespace(cache_dir="/root/lzw/tmp_0518_replay_cache0521_07/videos_cache", task_log_dir="/root/lzw/tmp_0518_replay_cache0521_07/tasks_log"), |
| 29 | save_frames_enable=True, | 29 | save_frames_enable=True, |
| 30 | ) | 30 | ) |
| 31 | 31 | ||
| @@ -45,8 +45,8 @@ def _base_data(): | @@ -45,8 +45,8 @@ def _base_data(): | ||
| 45 | }, | 45 | }, |
| 46 | "events": [ | 46 | "events": [ |
| 47 | {"id": "event_001", "type": "1", "url": url, "event_utc": 1777444502543-40000}, | 47 | {"id": "event_001", "type": "1", "url": url, "event_utc": 1777444502543-40000}, |
| 48 | - {"id": "event_001", "type": "1", "url": url, "event_utc": 1777444502543-20000}, | ||
| 49 | - {"id": "event_001", "type": "1", "url": url, "event_utc": 1777444531063+20000} | 48 | + {"id": "event_002", "type": "1", "url": url, "event_utc": 1777444502543-20000}, |
| 49 | + {"id": "event_003", "type": "1", "url": url, "event_utc": 1777444531063+20000} | ||
| 50 | ], | 50 | ], |
| 51 | } | 51 | } |
| 52 | 52 |
| @@ -102,10 +102,6 @@ class FootballReplayMatchLive: | @@ -102,10 +102,6 @@ class FootballReplayMatchLive: | ||
| 102 | record.append({"live": live, "llm_result": None, 'live_list': [live]}) | 102 | record.append({"live": live, "llm_result": None, 'live_list': [live]}) |
| 103 | return live | 103 | return live |
| 104 | user_contents = [] | 104 | user_contents = [] |
| 105 | - # replay_video_contents = video_contents(replay_video["video_path"], "\n【回放片段信息】\n", | ||
| 106 | - # prompt_end=f"\n回放解说内容:{replay_video['asr_text']}\n", | ||
| 107 | - # video_name=os.path.basename(replay_video["video_path"]), | ||
| 108 | - # fps=2, max_frames=999, sampling_mode="head", max_short_edge=480) | ||
| 109 | live_videos_contents = [] | 105 | live_videos_contents = [] |
| 110 | live_map = {} | 106 | live_map = {} |
| 111 | live_records = {} | 107 | live_records = {} |
| @@ -208,10 +204,10 @@ class FootballReplayMatchLive: | @@ -208,10 +204,10 @@ class FootballReplayMatchLive: | ||
| 208 | else: | 204 | else: |
| 209 | return None | 205 | return None |
| 210 | 206 | ||
| 211 | - def match_batch(self, replay_video: dict, live_videos: list[dict], max_parallel: int = 3, cache_dir=None): | 207 | + def match_batch(self, replay_video: dict, live_videos: list[dict], max_parallel: int = 3, cache_dir=None, task_log_dir=None): |
| 212 | 208 | ||
| 213 | self.cache_dir = cache_dir | 209 | self.cache_dir = cache_dir |
| 214 | - cache_path = os.path.join(cache_dir, 'match_live.json') | 210 | + cache_path = os.path.join(task_log_dir, 'match_live.json') |
| 215 | if cache_path is not None and os.path.exists(cache_path): | 211 | if cache_path is not None and os.path.exists(cache_path): |
| 216 | try: | 212 | try: |
| 217 | with open(cache_path, 'r', encoding='utf-8') as f: | 213 | with open(cache_path, 'r', encoding='utf-8') as f: |
| @@ -223,7 +219,7 @@ class FootballReplayMatchLive: | @@ -223,7 +219,7 @@ class FootballReplayMatchLive: | ||
| 223 | event_start = replay_video.get("start_utc", None) | 219 | event_start = replay_video.get("start_utc", None) |
| 224 | event_end = replay_video.get("end_utc", None) | 220 | event_end = replay_video.get("end_utc", None) |
| 225 | replay_video_contents = self.video2frame.to_llm_contents(replay_video_path, | 221 | replay_video_contents = self.video2frame.to_llm_contents(replay_video_path, |
| 226 | - cache=os.path.join(os.path.dirname(cache_dir), "replay"), | 222 | + cache=os.path.join(os.path.dirname(cache_dir), "replays"), |
| 227 | fps=2, | 223 | fps=2, |
| 228 | start=event_start, | 224 | start=event_start, |
| 229 | end=event_end, | 225 | end=event_end, |
| @@ -81,10 +81,10 @@ class FootballReplayVideoEvent: | @@ -81,10 +81,10 @@ class FootballReplayVideoEvent: | ||
| 81 | 81 | ||
| 82 | self.video2frame = Video2Frame(cache_dir=cache_dir, save_frames_enable=save_frames_enable) | 82 | self.video2frame = Video2Frame(cache_dir=cache_dir, save_frames_enable=save_frames_enable) |
| 83 | 83 | ||
| 84 | - def video_event(self, replay_pack: dict, asr_text: str = '无', cache_dir=None): | 84 | + def video_event(self, replay_pack: dict, asr_text: str = '无', cache_dir=None, task_log_dir=None): |
| 85 | replay_video_path = replay_pack.get("url", None) | 85 | replay_video_path = replay_pack.get("url", None) |
| 86 | 86 | ||
| 87 | - cache_path = os.path.join(cache_dir, 'video_event.json') | 87 | + cache_path = os.path.join(task_log_dir, 'video_event.json') |
| 88 | if cache_path is not None and os.path.exists(cache_path): | 88 | if cache_path is not None and os.path.exists(cache_path): |
| 89 | with open(cache_path, 'r', encoding='utf-8') as f: | 89 | with open(cache_path, 'r', encoding='utf-8') as f: |
| 90 | return json.loads(f.read()) | 90 | return json.loads(f.read()) |
| @@ -74,6 +74,7 @@ class Video2Frame: | @@ -74,6 +74,7 @@ class Video2Frame: | ||
| 74 | def to_frames(self, url, cache=None, fps=None, start=None, end=None, roi=None, max_px_area=None) -> list: | 74 | def to_frames(self, url, cache=None, fps=None, start=None, end=None, roi=None, max_px_area=None) -> list: |
| 75 | video_root_path = self.get_root_path(url, cache) | 75 | video_root_path = self.get_root_path(url, cache) |
| 76 | 76 | ||
| 77 | + video_root_path = video_root_path / f"{start}-{end}-{'_'.join(roi) if roi else 'None'}-{max_px_area}" | ||
| 77 | download_video_path = video_root_path / "video.mp4" | 78 | download_video_path = video_root_path / "video.mp4" |
| 78 | 79 | ||
| 79 | if not download_video_path.exists(): | 80 | if not download_video_path.exists(): |
| @@ -81,7 +82,9 @@ class Video2Frame: | @@ -81,7 +82,9 @@ class Video2Frame: | ||
| 81 | video_root_path.mkdir(parents=True, exist_ok=True) | 82 | video_root_path.mkdir(parents=True, exist_ok=True) |
| 82 | download_to_mp4(url, str(download_video_path), duration=None) | 83 | download_to_mp4(url, str(download_video_path), duration=None) |
| 83 | logger.info(f"video_path: {download_video_path}") | 84 | logger.info(f"video_path: {download_video_path}") |
| 84 | - cache_dir = video_root_path / 'caches' / f"{start}-{end}-{'_'.join(roi) if roi else 'None'}-{max_px_area}" | 85 | + |
| 86 | + | ||
| 87 | + cache_dir = video_root_path | ||
| 85 | cache_frames = cache_dir / "frames" | 88 | cache_frames = cache_dir / "frames" |
| 86 | cache_name = cache_dir / "data.json" | 89 | cache_name = cache_dir / "data.json" |
| 87 | 90 |
-
Please register or login to post a comment