️ perf: NAS 图搜 k=150、缩略图并行生成
- filesystem.search.ransac_top_k 200→150(柴进 1119 拍板):k=500 覆盖 725 中保留 718(k=200 为 721),重排预计 ~2.8s - 前 thumbnail_top_n 张缩略图改线程池并行(threads=4),结果顺序与 stale 标记不变 - 全量 120 passed / 1 skipped Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Showing
3 changed files
with
16 additions
and
7 deletions
| ... | @@ -30,7 +30,7 @@ filesystem: | ... | @@ -30,7 +30,7 @@ filesystem: |
| 30 | subject: nas-image-search | 30 | subject: nas-image-search |
| 31 | search: | 31 | search: |
| 32 | max_candidates: 2000 | 32 | max_candidates: 2000 |
| 33 | ransac_top_k: 200 # D6: keeps 721/725 (99.4%) of k=500 recall coverage; single rerank 3.7s vs 9.2s. | 33 | ransac_top_k: 150 # 1119 Chaijin: speed over 3 variants; covers 718/725 of k=500 (k=200: 721); rerank est. ~2.8s (k=100 1.9s, k=200 3.7s measured). |
| 34 | ransac: | 34 | ransac: |
| 35 | min_inliers: 8 | 35 | min_inliers: 8 |
| 36 | reproj_threshold: 6.0 | 36 | reproj_threshold: 6.0 | ... | ... |
| ... | @@ -130,15 +130,24 @@ class ImageSearchEngine: | ... | @@ -130,15 +130,24 @@ class ImageSearchEngine: |
| 130 | result.update(path=row['image_url'], thumbnail=None) | 130 | result.update(path=row['image_url'], thumbnail=None) |
| 131 | if row['frame_ms'] != -1: | 131 | if row['frame_ms'] != -1: |
| 132 | result['frame_ms'] = row['frame_ms'] | 132 | result['frame_ms'] = row['frame_ms'] |
| 133 | if len(results) < self.thumbnail_top_n: | 133 | results.append(result) |
| 134 | rows = [candidate['metadata'] for candidate in list(distinct.values())[:self.thumbnail_top_n]] | ||
| 135 | # 缩略图逐张解码 NAS 原图(大 TIFF 可达数秒),并行生成;结果顺序不变。 | ||
| 136 | with ThreadPoolExecutor(max_workers=self.threads) as executor: | ||
| 137 | for result, thumbnail in zip(results, executor.map(self._thumbnail, rows)): | ||
| 138 | if thumbnail is None: | ||
| 139 | result['stale'] = True | ||
| 140 | else: | ||
| 141 | result['thumbnail'] = thumbnail | ||
| 142 | return results | ||
| 143 | |||
| 144 | def _thumbnail(self, row): | ||
| 134 | try: | 145 | try: |
| 135 | thumbnail = jpeg_thumbnail(row['path'], self.file_paths.root_for(row['path']), | 146 | thumbnail = jpeg_thumbnail(row['path'], self.file_paths.root_for(row['path']), |
| 136 | (row['mtime'], row['size']), row['frame_ms']) | 147 | (row['mtime'], row['size']), row['frame_ms']) |
| 137 | result['thumbnail'] = b64encode(thumbnail).decode('ascii') | 148 | return b64encode(thumbnail).decode('ascii') |
| 138 | except (OSError, ValueError, Image.DecompressionBombError, cv2.error): | 149 | except (OSError, ValueError, Image.DecompressionBombError, cv2.error): |
| 139 | result['stale'] = True | 150 | return None |
| 140 | results.append(result) | ||
| 141 | return results | ||
| 142 | 151 | ||
| 143 | def _assess_confidence(self, candidate): | 152 | def _assess_confidence(self, candidate): |
| 144 | """ | 153 | """ | ... | ... |
| ... | @@ -136,7 +136,7 @@ def test_filesystem_engine_uses_default_config_k_and_wal(tmp_path): | ... | @@ -136,7 +136,7 @@ def test_filesystem_engine_uses_default_config_k_and_wal(tmp_path): |
| 136 | unc_prefixes={str(tmp_path): r'\\nas\test'}) | 136 | unc_prefixes={str(tmp_path): r'\\nas\test'}) |
| 137 | path = tmp_path / 'files.db' | 137 | path = tmp_path / 'files.db' |
| 138 | engine = ImageSearchEngine(db_path=path, config=config, extractor=Extractor()) | 138 | engine = ImageSearchEngine(db_path=path, config=config, extractor=Extractor()) |
| 139 | assert engine.ransac_top_k == 200 | 139 | assert engine.ransac_top_k == 150 |
| 140 | with engine.db.get_connection() as conn: | 140 | with engine.db.get_connection() as conn: |
| 141 | assert conn.execute('PRAGMA journal_mode').fetchone()[0] == 'wal' | 141 | assert conn.execute('PRAGMA journal_mode').fetchone()[0] == 'wal' |
| 142 | 142 | ... | ... |
-
Please register or sign in to post a comment