模型添加置信度设置,敏感词分页
This commit is contained in:
15
core/yolo.py
15
core/yolo.py
@ -1,5 +1,5 @@
|
||||
from ultralytics import YOLO
|
||||
from service.model_service import get_current_yolo_model # 带版本校验的模型获取
|
||||
from service.model_service import get_current_yolo_model, get_current_conf_threshold # 新增置信度获取函数
|
||||
|
||||
|
||||
def load_model(model_path=None):
|
||||
@ -15,8 +15,8 @@ def load_model(model_path=None):
|
||||
return None
|
||||
|
||||
|
||||
def detect(frame, conf_threshold=0.7):
|
||||
"""执行目标检测(仅模型版本变化时重新加载,平时复用缓存)"""
|
||||
def detect(frame):
|
||||
"""执行目标检测(使用动态置信度,仅模型版本变化时重新加载)"""
|
||||
# 获取模型(内部已做版本校验,未变化则直接返回缓存)
|
||||
current_model = load_model()
|
||||
if not current_model:
|
||||
@ -26,6 +26,8 @@ def detect(frame, conf_threshold=0.7):
|
||||
return (False, "无效输入帧")
|
||||
|
||||
try:
|
||||
# 获取动态置信度(从全局配置中读取)
|
||||
conf_threshold = get_current_conf_threshold()
|
||||
# 用当前模型执行检测(复用缓存,无额外加载耗时)
|
||||
results = current_model(frame, conf=conf_threshold, verbose=False)
|
||||
has_results = len(results[0].boxes) > 0 if results else False
|
||||
@ -43,13 +45,8 @@ def detect(frame, conf_threshold=0.7):
|
||||
class_name = current_model.names[cls] if hasattr(current_model, 'names') else f"类别{cls}"
|
||||
result_parts.append(f"{class_name}(置信度:{conf:.2f},位置:{bbox})")
|
||||
|
||||
# 打印当前使用的模型路径和版本(用于验证)
|
||||
# model_path = getattr(current_model, "model_path", "未知路径")
|
||||
# from service.model_service import _current_model_version
|
||||
# print(f"[YOLO检测] 使用模型:{model_path}(版本:{_current_model_version[:10]}...)")
|
||||
|
||||
return (True, "; ".join(result_parts))
|
||||
|
||||
except Exception as e:
|
||||
print(f"YOLO检测过程出错:{str(e)}")
|
||||
return (False, f"检测错误:{str(e)}")
|
||||
return (False, f"检测错误:{str(e)}")
|
||||
Reference in New Issue
Block a user