fix: optimize diagnosis output format and fix inconsistency between fault_status and fault_type
1. 输出格式优化: - faults中移除冗余的bbox和confidence字段 - summary中fault_count改名为detection_count 2. fault_status与fault_type逻辑统一: - normal状态时fault_type为'none',不再使用'suspect' - abnormal状态时才进行故障类型分类(hotspot/local_overheating/overheat) 3. 修复usage_example.py图像通道问题: - YOLO检测使用彩色图,温度提取时再转灰度图
This commit is contained in:
+1
-3
@@ -222,15 +222,13 @@
|
|||||||
"image": "FLIR0150.jpg",
|
"image": "FLIR0150.jpg",
|
||||||
"detections": [...],
|
"detections": [...],
|
||||||
"faults": [{
|
"faults": [{
|
||||||
"bbox": [...],
|
|
||||||
"confidence": 0.995,
|
|
||||||
"temp_max": 255.0,
|
"temp_max": 255.0,
|
||||||
"fault_status": "abnormal",
|
"fault_status": "abnormal",
|
||||||
"fault_type": "hotspot"
|
"fault_type": "hotspot"
|
||||||
}],
|
}],
|
||||||
"summary": {
|
"summary": {
|
||||||
"status": "fault_detected",
|
"status": "fault_detected",
|
||||||
"fault_count": 1,
|
"detection_count": 1,
|
||||||
"abnormal_count": 1
|
"abnormal_count": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -279,8 +279,6 @@ print(f"故障类型: {result['summary']['fault_types']}")
|
|||||||
],
|
],
|
||||||
"faults": [
|
"faults": [
|
||||||
{
|
{
|
||||||
"bbox": [x1, y1, x2, y2],
|
|
||||||
"confidence": 0.995,
|
|
||||||
"temp_max": 255.0,
|
"temp_max": 255.0,
|
||||||
"temp_mean": 97.49,
|
"temp_mean": 97.49,
|
||||||
"temp_std": 45.2,
|
"temp_std": 45.2,
|
||||||
@@ -290,7 +288,7 @@ print(f"故障类型: {result['summary']['fault_types']}")
|
|||||||
],
|
],
|
||||||
"summary": {
|
"summary": {
|
||||||
"status": "fault_detected",
|
"status": "fault_detected",
|
||||||
"fault_count": 1,
|
"detection_count": 1,
|
||||||
"abnormal_count": 1,
|
"abnormal_count": 1,
|
||||||
"fault_types": ["hotspot"]
|
"fault_types": ["hotspot"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,10 +52,13 @@ def example3_temperature_extraction():
|
|||||||
detector = InfraredDetector("weights/best.pt")
|
detector = InfraredDetector("weights/best.pt")
|
||||||
|
|
||||||
# 读取图像
|
# 读取图像
|
||||||
gray_img = cv2.imread(SAMPLE_IMAGE, cv2.IMREAD_GRAYSCALE)
|
color_img = cv2.imread(SAMPLE_IMAGE, cv2.IMREAD_COLOR)
|
||||||
|
|
||||||
# 检测目标(复用已加载的图像)
|
# 检测目标(彩色图)
|
||||||
detections = detector.detect(gray_img)
|
detections = detector.detect(color_img)
|
||||||
|
|
||||||
|
# 转为灰度图用于温度提取
|
||||||
|
gray_img = cv2.cvtColor(color_img, cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
# 提取第一个检测框的温度特征
|
# 提取第一个检测框的温度特征
|
||||||
if detections:
|
if detections:
|
||||||
|
|||||||
+8
-8
@@ -67,13 +67,13 @@ class FaultDiagnoser:
|
|||||||
|
|
||||||
fault_status = self._check_fault(temp_features)
|
fault_status = self._check_fault(temp_features)
|
||||||
temp_features['fault_status'] = fault_status
|
temp_features['fault_status'] = fault_status
|
||||||
temp_features['fault_type'] = self._classify_fault(temp_features)
|
# abnormal 时才进行故障分类,normal 时类型为 none
|
||||||
|
if fault_status == 'abnormal':
|
||||||
|
temp_features['fault_type'] = self._classify_fault(temp_features)
|
||||||
|
else:
|
||||||
|
temp_features['fault_type'] = 'none'
|
||||||
|
|
||||||
result['faults'].append({
|
result['faults'].append(temp_features)
|
||||||
'bbox': bbox,
|
|
||||||
'confidence': det['confidence'],
|
|
||||||
**temp_features
|
|
||||||
})
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Detector not initialized with model")
|
raise ValueError("Detector not initialized with model")
|
||||||
|
|
||||||
@@ -137,14 +137,14 @@ class FaultDiagnoser:
|
|||||||
摘要信息
|
摘要信息
|
||||||
"""
|
"""
|
||||||
if not faults:
|
if not faults:
|
||||||
return {'status': 'no_detection', 'fault_count': 0}
|
return {'status': 'no_detection', 'detection_count': 0}
|
||||||
|
|
||||||
abnormal_count = sum(1 for f in faults if f.get('fault_status') == 'abnormal')
|
abnormal_count = sum(1 for f in faults if f.get('fault_status') == 'abnormal')
|
||||||
fault_types = [f.get('fault_type', 'unknown') for f in faults]
|
fault_types = [f.get('fault_type', 'unknown') for f in faults]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'status': 'fault_detected' if abnormal_count > 0 else 'normal',
|
'status': 'fault_detected' if abnormal_count > 0 else 'normal',
|
||||||
'fault_count': len(faults),
|
'detection_count': len(faults),
|
||||||
'abnormal_count': abnormal_count,
|
'abnormal_count': abnormal_count,
|
||||||
'fault_types': list(set(fault_types))
|
'fault_types': list(set(fault_types))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user