Spaces:
Running
on
Zero
Running
on
Zero
Update scene_analyzer.py
Browse files- scene_analyzer.py +10 -11
scene_analyzer.py
CHANGED
|
@@ -72,10 +72,9 @@ class SceneAnalyzer:
|
|
| 72 |
"""
|
| 73 |
Use new implement
|
| 74 |
"""
|
| 75 |
-
#
|
| 76 |
functional_zones = self.spatial_analyzer._identify_functional_zones(detected_objects, scene_type)
|
| 77 |
|
| 78 |
-
# 使用增強的場景描述生成器
|
| 79 |
return self.generate_scene_description(
|
| 80 |
scene_type,
|
| 81 |
detected_objects,
|
|
@@ -123,7 +122,7 @@ class SceneAnalyzer:
|
|
| 123 |
"regions": {},
|
| 124 |
"possible_activities": [],
|
| 125 |
"safety_concerns": [],
|
| 126 |
-
"lighting_conditions": lighting_info or {"time_of_day": "unknown", "confidence": 0
|
| 127 |
}
|
| 128 |
|
| 129 |
# Get class names from detection result if not already set
|
|
@@ -149,7 +148,7 @@ class SceneAnalyzer:
|
|
| 149 |
"regions": {},
|
| 150 |
"possible_activities": [],
|
| 151 |
"safety_concerns": [],
|
| 152 |
-
"lighting_conditions": lighting_info or {"time_of_day": "unknown", "confidence": 0
|
| 153 |
}
|
| 154 |
|
| 155 |
# Analyze object distribution in regions
|
|
@@ -257,7 +256,7 @@ class SceneAnalyzer:
|
|
| 257 |
# 添加 CLIP 特定的結果(新增)
|
| 258 |
if clip_analysis and "error" not in clip_analysis:
|
| 259 |
result["clip_analysis"] = {
|
| 260 |
-
"top_scene": clip_analysis.get("top_scene", ("unknown", 0
|
| 261 |
"cultural_analysis": clip_analysis.get("cultural_analysis", {})
|
| 262 |
}
|
| 263 |
|
|
@@ -375,15 +374,15 @@ class SceneAnalyzer:
|
|
| 375 |
|
| 376 |
for scene_type in all_scene_types:
|
| 377 |
# 獲取兩個模型的分數
|
| 378 |
-
yolo_score = yolo_scene_scores.get(scene_type, 0
|
| 379 |
-
clip_score = clip_scene_scores.get(scene_type, 0
|
| 380 |
|
| 381 |
# 設置基本權重
|
| 382 |
-
yolo_weight = 0.7 # YOLO
|
| 383 |
-
clip_weight = 0.3 # CLIP
|
| 384 |
|
| 385 |
# 對特定類型場景調整權重
|
| 386 |
-
# 文化特定場景或具有特殊布局的場景,CLIP
|
| 387 |
if any(keyword in scene_type for keyword in ["asian", "cultural", "aerial"]):
|
| 388 |
yolo_weight = 0.3
|
| 389 |
clip_weight = 0.7
|
|
@@ -393,7 +392,7 @@ class SceneAnalyzer:
|
|
| 393 |
yolo_weight = 0.8
|
| 394 |
clip_weight = 0.2
|
| 395 |
elif scene_type == "beach_water_recreation":
|
| 396 |
-
yolo_weight = 0.8 #
|
| 397 |
clip_weight = 0.2
|
| 398 |
elif scene_type == "sports_venue":
|
| 399 |
yolo_weight = 0.7
|
|
|
|
| 72 |
"""
|
| 73 |
Use new implement
|
| 74 |
"""
|
| 75 |
+
# get the functional zones info
|
| 76 |
functional_zones = self.spatial_analyzer._identify_functional_zones(detected_objects, scene_type)
|
| 77 |
|
|
|
|
| 78 |
return self.generate_scene_description(
|
| 79 |
scene_type,
|
| 80 |
detected_objects,
|
|
|
|
| 122 |
"regions": {},
|
| 123 |
"possible_activities": [],
|
| 124 |
"safety_concerns": [],
|
| 125 |
+
"lighting_conditions": lighting_info or {"time_of_day": "unknown", "confidence": 0}
|
| 126 |
}
|
| 127 |
|
| 128 |
# Get class names from detection result if not already set
|
|
|
|
| 148 |
"regions": {},
|
| 149 |
"possible_activities": [],
|
| 150 |
"safety_concerns": [],
|
| 151 |
+
"lighting_conditions": lighting_info or {"time_of_day": "unknown", "confidence": 0}
|
| 152 |
}
|
| 153 |
|
| 154 |
# Analyze object distribution in regions
|
|
|
|
| 256 |
# 添加 CLIP 特定的結果(新增)
|
| 257 |
if clip_analysis and "error" not in clip_analysis:
|
| 258 |
result["clip_analysis"] = {
|
| 259 |
+
"top_scene": clip_analysis.get("top_scene", ("unknown", 0)),
|
| 260 |
"cultural_analysis": clip_analysis.get("cultural_analysis", {})
|
| 261 |
}
|
| 262 |
|
|
|
|
| 374 |
|
| 375 |
for scene_type in all_scene_types:
|
| 376 |
# 獲取兩個模型的分數
|
| 377 |
+
yolo_score = yolo_scene_scores.get(scene_type, 0)
|
| 378 |
+
clip_score = clip_scene_scores.get(scene_type, 0)
|
| 379 |
|
| 380 |
# 設置基本權重
|
| 381 |
+
yolo_weight = 0.7 # YOLO 可提供比較好的物體資訊
|
| 382 |
+
clip_weight = 0.3 # CLIP 強項是理解整體的場景關係
|
| 383 |
|
| 384 |
# 對特定類型場景調整權重
|
| 385 |
+
# 文化特定場景或具有特殊布局的場景,CLIP可能比較能理解
|
| 386 |
if any(keyword in scene_type for keyword in ["asian", "cultural", "aerial"]):
|
| 387 |
yolo_weight = 0.3
|
| 388 |
clip_weight = 0.7
|
|
|
|
| 392 |
yolo_weight = 0.8
|
| 393 |
clip_weight = 0.2
|
| 394 |
elif scene_type == "beach_water_recreation":
|
| 395 |
+
yolo_weight = 0.8 # 衝浪板等特定物品的檢測
|
| 396 |
clip_weight = 0.2
|
| 397 |
elif scene_type == "sports_venue":
|
| 398 |
yolo_weight = 0.7
|