Przeglądaj źródła

优化AI长连接、修改AI目标置信度

zhangdongming 2 lat temu
rodzic
commit
894b15bfbf
1 zmienionych plików z 8 dodań i 7 usunięć
  1. 8 7
      Controller/AiController.py

+ 8 - 7
Controller/AiController.py

@@ -24,6 +24,8 @@ from Service.PushService import PushObject
 LOGGING = logging.getLogger('info')
 CLOUD_BASED_AI_URL = '34.192.147.108:8001'
 MODEL_NAME = 'AI_5obj_pdcpv_detect_yolov5_pipeline'
+# 建立长连接
+ai_connect = AiEngine(url=CLOUD_BASED_AI_URL)
 
 
 class AiView(View):
@@ -105,7 +107,7 @@ class AiView(View):
                     f.write(val)
                     f.close()
             ai_view = AiView()
-            ai_results = ai_view.image_aI_recognition(file_path_list, 0.45, 0.45, 1)
+            ai_results = ai_view.image_aI_recognition(file_path_list, 0.45, 0.55, 1)
             if not ai_results:
                 CommonService.del_path(dir_path)
                 return response.json(0)
@@ -222,22 +224,21 @@ class AiView(View):
         :return: results 推理结果
         """
         try:
-            # 建立长连接
-            ai = AiEngine(url=CLOUD_BASED_AI_URL)
+
             # 检查连通性、推理服务器状态
-            if ai.health:
+            if ai_connect.health:
                 LOGGING.info('健康状况通过')
             # 设定模型
-            if ai.set_model(MODEL_NAME):
+            if ai_connect.set_model(MODEL_NAME):
                 LOGGING.info('设置模型通过')
             # 推理张数(一次最多推理128张!)
             # 图片名称(这里可以改成内存)注意改完之后要检查input_tmp的【类型(type)、尺寸(shape)】是否和之前的一致
             # 输入尺寸固定640wx360h,如需变动可以联系我们,我们这边做resize会快
             input_name_arr = np.array(list(map(np.array, map(Image.open, input_name_arr))))
             # 推理
-            results = ai.yolo_infer(input_name_arr, nms_threshold, confidence, client_timeout)
+            results = ai_connect.yolo_infer(input_name_arr, nms_threshold, confidence, client_timeout)
             # 推理完请关闭长连接
-            ai.close()
+            ai_connect.close()
             # 报错返回
             if results == 'e_timeout':
                 raise Exception('推理超时')