From 085cbc995079cfb33fab1285f22bca7ea5b30ac3 Mon Sep 17 00:00:00 2001 From: SkyLi Date: Fri, 27 Mar 2026 12:03:48 +0800 Subject: [PATCH] fix: optimize diagnosis output format and fix inconsistency between fault_status and fault_type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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检测使用彩色图,温度提取时再转灰度图 --- PROGRESS.md | 4 +--- README.md | 4 +--- scripts/usage_example.py | 9 ++++++--- src/diagnose.py | 16 ++++++++-------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/PROGRESS.md b/PROGRESS.md index f1becf8..24f6649 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -222,15 +222,13 @@ "image": "FLIR0150.jpg", "detections": [...], "faults": [{ - "bbox": [...], - "confidence": 0.995, "temp_max": 255.0, "fault_status": "abnormal", "fault_type": "hotspot" }], "summary": { "status": "fault_detected", - "fault_count": 1, + "detection_count": 1, "abnormal_count": 1 } } diff --git a/README.md b/README.md index 6ba3616..ce5a962 100644 --- a/README.md +++ b/README.md @@ -279,8 +279,6 @@ print(f"故障类型: {result['summary']['fault_types']}") ], "faults": [ { - "bbox": [x1, y1, x2, y2], - "confidence": 0.995, "temp_max": 255.0, "temp_mean": 97.49, "temp_std": 45.2, @@ -290,7 +288,7 @@ print(f"故障类型: {result['summary']['fault_types']}") ], "summary": { "status": "fault_detected", - "fault_count": 1, + "detection_count": 1, "abnormal_count": 1, "fault_types": ["hotspot"] } diff --git a/scripts/usage_example.py b/scripts/usage_example.py index c3c2abb..c5bb052 100644 --- a/scripts/usage_example.py +++ b/scripts/usage_example.py @@ -52,10 +52,13 @@ def example3_temperature_extraction(): 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: diff --git a/src/diagnose.py b/src/diagnose.py index 356df7f..5a5ce43 100644 --- a/src/diagnose.py +++ b/src/diagnose.py @@ -67,13 +67,13 @@ class FaultDiagnoser: fault_status = self._check_fault(temp_features) 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({ - 'bbox': bbox, - 'confidence': det['confidence'], - **temp_features - }) + result['faults'].append(temp_features) else: raise ValueError("Detector not initialized with model") @@ -137,14 +137,14 @@ class FaultDiagnoser: 摘要信息 """ 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') fault_types = [f.get('fault_type', 'unknown') for f in faults] return { 'status': 'fault_detected' if abnormal_count > 0 else 'normal', - 'fault_count': len(faults), + 'detection_count': len(faults), 'abnormal_count': abnormal_count, 'fault_types': list(set(fault_types)) }