qwen_detect.py
@@ -30,7 +30,7 @@
                    # 将键值对添加到字典中
                    self.config[key] = value
        # 创建实例专属logger
        os.makedirs("logs", exist_ok=True)
        os.makedirs(self.config.get("logaddr"), exist_ok=True)
        logging.basicConfig(
            level=logging.INFO,
            format='%(asctime)s - %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s: %(message)s',
@@ -38,7 +38,7 @@
            handlers=[
                # 按大小轮转的日志文件(最大10MB,保留3个备份)
                RotatingFileHandler(
                    filename=os.path.join("logs", 'qwen_log.log'),
                    filename=os.path.join(self.config.get("logaddr"), 'qwen_log.log'),
                    maxBytes=10 * 1024 * 1024,  # 10MB
                    backupCount=3,
                    encoding='utf-8'
@@ -106,39 +106,36 @@
                # image_id = get_mem.smem_read_frame_qianwen(camera_id)
                if len(res_a) > 0:
                    sorted_results = sorted(res_a, key=itemgetter("id"), reverse=True)
                    # 查询前N个最大的ID
                    num = int(self.config.get("threadnum")) - 1
                    res_a = sorted_results[:num]
                    for res in res_a:
                        data = {
                            "id": res['id'],
                            "event_level_id": res['event_level_id'],  # event_level_id
                            "event_level_name": res['event_level_name'],  # event_level_id
                            "rule_id": res["rule_id"],
                            "video_point_id": res['video_point_id'],  # video_point_id
                            "video_point_name": res['video_point_name'],
                            "is_waning": 0,
                            "is_desc": 1,
                            "zh_desc_class": res['zh_desc_class'],  # text_vector
                            "bounding_box": res['bounding_box'],  # bounding_box
                            "task_id": res['task_id'],  # task_id
                            "task_name": res['task_name'],  # task_id
                            "detect_id": res['detect_id'],  # detect_id
                            "detect_time": res['detect_time'],  # detect_time
                            "detect_num": res['detect_num'],
                            "waning_value": res['waning_value'],
                            "image_path": res['image_path'],  # image_path
                            "image_desc_path": res['image_desc_path'],  # image_desc_path
                            "video_path": res['video_path'],
                            "text_vector": res['text_vector'],
                            "knowledge_id": res['knowledge_id'],
                            "suggestion": res['suggestion'],
                        }
                        # logging.info(f"读取图像成功: {res['id']}")
                        # 保存到milvus
                        image_id = self.collection.upsert(data).primary_keys
                        res['id'] = image_id[0]
                        self.pool.submit(res)
                    res = sorted_results[0]
                    data = {
                        "id": res['id'],
                        "event_level_id": res['event_level_id'],  # event_level_id
                        "event_level_name": res['event_level_name'],  # event_level_id
                        "rule_id": res["rule_id"],
                        "video_point_id": res['video_point_id'],  # video_point_id
                        "video_point_name": res['video_point_name'],
                        "is_waning": 0,
                        "is_desc": 1,
                        "zh_desc_class": res['zh_desc_class'],  # text_vector
                        "bounding_box": res['bounding_box'],  # bounding_box
                        "task_id": res['task_id'],  # task_id
                        "task_name": res['task_name'],  # task_id
                        "detect_id": res['detect_id'],  # detect_id
                        "detect_time": res['detect_time'],  # detect_time
                        "detect_num": res['detect_num'],
                        "waning_value": res['waning_value'],
                        "image_path": res['image_path'],  # image_path
                        "image_desc_path": res['image_desc_path'],  # image_desc_path
                        "video_path": res['video_path'],
                        "text_vector": res['text_vector'],
                        "knowledge_id": res['knowledge_id'],
                        "suggestion": res['suggestion'],
                    }
                    # logging.info(f"读取图像成功: {res['id']}")
                    # 保存到milvus
                    image_id = self.collection.upsert(data).primary_keys
                    res['id'] = image_id[0]
                    self.pool.submit(res)
            except Exception as e:
                logging.info(f"{camera_id}线程错误:{e}")
            time_sel.sleep(0.01)