- Remove session-ses_2f27.md (161KB raw session log) - Remove 49 ROOT_* duplicate files across REFERENCE/ - Remove 14 duplicate files between REFERENCE/ root and history/ - Remove asr_legacy.rs (dead code, replaced by asr.rs) - Remove src/core/worker/ (duplicate JobWorker) - Remove src/core/layers/ (empty directory) - Remove 4 .bak files in src/ - Remove 7 dead private methods in worker/processor.rs - Remove backup directory from git tracking
130 lines
3.6 KiB
Python
130 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
||
"""測試 Places365 場景識別功能"""
|
||
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
# 添加腳本目錄到路徑
|
||
script_dir = Path(__file__).parent
|
||
sys.path.insert(0, str(script_dir))
|
||
|
||
from scene_classifier import SceneClassifier, PLACES365_CATEGORIES
|
||
|
||
|
||
def test_places365_categories():
|
||
"""測試 Places365 類別載入"""
|
||
print("=== 測試 Places365 類別 ===\n")
|
||
|
||
if not PLACES365_CATEGORIES:
|
||
print("✗ Places365 類別未載入")
|
||
return False
|
||
|
||
print(f"✓ 載入 {len(PLACES365_CATEGORIES)} 個場景類別")
|
||
|
||
# 顯示前 10 個類別
|
||
print("\n前 10 個場景類別:")
|
||
for i in range(min(10, len(PLACES365_CATEGORIES))):
|
||
key = str(i)
|
||
if key in PLACES365_CATEGORIES:
|
||
print(f" {i}. {PLACES365_CATEGORIES[key]}")
|
||
|
||
return True
|
||
|
||
|
||
def test_scene_classifier():
|
||
"""測試場景分類器基本功能"""
|
||
print("\n=== 測試場景分類器 ===\n")
|
||
|
||
classifier = SceneClassifier()
|
||
|
||
if not classifier.load_model():
|
||
print("✗ 模型載入失敗")
|
||
return False
|
||
|
||
print("✓ 模型載入成功")
|
||
print(
|
||
f" 模型類型:{'PyTorch' if classifier.model else 'Core ML' if classifier.coreml_model else 'None'}"
|
||
)
|
||
|
||
return True
|
||
|
||
|
||
def test_video_classification(video_path: str):
|
||
"""測試影片場景分類"""
|
||
print("\n=== 測試影片場景分類 ===\n")
|
||
print(f"影片:{video_path}")
|
||
|
||
if not Path(video_path).exists():
|
||
print(f"✗ 影片檔案不存在:{video_path}")
|
||
return False
|
||
|
||
classifier = SceneClassifier()
|
||
if not classifier.load_model():
|
||
print("✗ 模型載入失敗")
|
||
return False
|
||
|
||
# 執行分類
|
||
result = classifier.classify_video(
|
||
video_path=video_path,
|
||
output_path="/tmp/test_scene_output.json",
|
||
sample_interval=2.0,
|
||
min_scene_duration=3.0,
|
||
)
|
||
|
||
# 顯示結果
|
||
print("\n✓ 分類完成")
|
||
print(f" 場景數量:{len(result['scenes'])}")
|
||
|
||
if result["scenes"]:
|
||
scene = result["scenes"][0]
|
||
print("\n主要場景:")
|
||
print(f" 類型:{scene['scene_type']}")
|
||
print(f" 中文:{scene.get('scene_type_zh', 'N/A')}")
|
||
print(f" 持續時間:{scene['end_time'] - scene['start_time']:.1f} 秒")
|
||
print(f" 信心度:{scene['confidence'] * 100:.1f}%")
|
||
|
||
if scene.get("top_5"):
|
||
print("\nTop 5 預測:")
|
||
for i, pred in enumerate(scene["top_5"][:3]):
|
||
print(
|
||
f" {i + 1}. {pred['scene_type']} ({pred['confidence'] * 100:.1f}%)"
|
||
)
|
||
|
||
return True
|
||
|
||
|
||
def main():
|
||
"""主測試函數"""
|
||
print("Places365 場景識別測試\n")
|
||
print("=" * 50)
|
||
|
||
# 測試 1: Places365 類別
|
||
if not test_places365_categories():
|
||
print("\n⚠️ Places365 類別測試失敗,但可繼續使用")
|
||
|
||
# 測試 2: 場景分類器
|
||
if not test_scene_classifier():
|
||
print("\n✗ 場景分類器測試失敗")
|
||
return 1
|
||
|
||
# 測試 3: 影片分類(如果有提供)
|
||
if len(sys.argv) > 1:
|
||
video_path = sys.argv[1]
|
||
if not test_video_classification(video_path):
|
||
print("\n⚠️ 影片分類測試失敗")
|
||
|
||
print("\n" + "=" * 50)
|
||
print("✓ 所有測試完成!")
|
||
print("\n下一步:")
|
||
print(
|
||
"1. 使用場景識別:python3 scripts/scene_classifier.py <video.mp4> <output.json>"
|
||
)
|
||
print("2. 查看安裝指南:cat docs/PLACES365_INSTALLATION.md")
|
||
print("3. 下載 Places365 模型以提升準確率")
|
||
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|