Parcourir la source

推理接口修改以及端口修改

袁威 il y a 1 semaine
Parent
commit
05a92708fa
3 fichiers modifiés avec 22 ajouts et 2 suppressions
  1. 1 1
      Test/推理和存储.py
  2. 20 0
      app/services/score_service.py
  3. 1 1
      run_defect_score_server.py

+ 1 - 1
Test/推理和存储.py

@@ -4,7 +4,7 @@ import os
 
 # --- 服务地址配置 ---
 # 第一个服务: 卡片评分/缺陷推理
-SCORE_API_URL = 'http://127.0.0.1:7744/api/card_score/score_inference'
+SCORE_API_URL = 'http://127.0.0.1:7754/api/card_score/score_inference'
 # 第二个服务: 结果存储
 STORAGE_API_URL = 'http://192.168.31.243:7745/api/image_data/insert'
 

+ 20 - 0
app/services/score_service.py

@@ -114,6 +114,20 @@ class ScoreService:
         logger.info("分数推理完成 ")
         return result_json
 
+    @staticmethod
+    def _has_valid_center_box(center_json: dict) -> bool:
+        """判断 center_result 是否包含可用于居中重算的内外框 shapes。
+
+        StitchFusion(同轴光)输出的 center_result 里 inner_box/outer_box 的 shapes 为空,
+        无法做居中重算; 此时应降级为只算面缺陷, 避免索引空列表报错。
+        """
+        if not center_json:
+            return False
+        box_result = center_json.get('box_result') or {}
+        inner_shapes = (box_result.get('inner_box') or {}).get('shapes') or []
+        outer_shapes = (box_result.get('outer_box') or {}).get('shapes') or []
+        return len(inner_shapes) > 0 and len(outer_shapes) > 0
+
     def recalculate_defect_score(self, score_type: str, json_data: dict):
 
         center_json_data = json_data["result"]['center_result']
@@ -132,6 +146,12 @@ class ScoreService:
         else:
             card_light_type = "coaxial"
 
+        # 环光重算依赖 center_result 的内外框; 若缺失(如同轴光/StitchFusion 数据),
+        # 自动降级为同轴光面缺陷重算, 避免 list index out of range。
+        if card_light_type == 'ring' and not self._has_valid_center_box(center_json_data):
+            logger.warning("score_type 为环光但 center_result 无有效内外框, 自动降级为同轴光(coaxial)面缺陷重算")
+            card_light_type = "coaxial"
+
         logger.info("开始进行缺陷信息重计算")
         defect_data = self.defect_service.re_inference_from_json(card_light_type=card_light_type,
                                                                  center_json=center_json_data,

+ 1 - 1
run_defect_score_server.py

@@ -1,6 +1,6 @@
 import uvicorn
 
 if __name__ == "__main__":
-    port = 7744
+    port = 7754
     print(f"http://127.0.0.1:{port}/docs")
     uvicorn.run("app.main:app", host="0.0.0.0", port=port, reload=True)