违停检测模型改为yolov8s,检测模式修改为手动框选禁停区域

This commit is contained in:
2026-06-15 09:22:07 +08:00
parent 18cfc9b16a
commit 4283fb1332
8 changed files with 492 additions and 358 deletions
+29 -20
View File
@@ -102,22 +102,22 @@ class ModelService:
'name': '徘徊检测'
},
'vehicle_detection': {
'path': os.path.join(base_dir, 'models', 'vehicle_detection_paddle', 'mot_ppyoloe_l_36e_ppvehicle', 'model.pdmodel'),
'type': 'paddle',
'classes': ['vehicle'],
'labels': {'vehicle': ''},
'size': '181MB',
'description': '基于PaddlePaddle PP-YOLOE-l的车辆检测和跟踪模型',
'name': '车辆检测 (Paddle)'
'path': os.path.join(base_dir, 'models', 'vehicle_detection_paddle', 'yolov8s.pt'),
'type': 'yolov8',
'classes': ['car', 'truck', 'bus', 'motorcycle'],
'labels': {'car': '小汽车', 'truck': '卡车', 'bus': '公交车', 'motorcycle': '摩托'},
'size': '23MB',
'description': '基于YOLOv8s的园区车辆检测模型(COCO预训练)',
'name': '车辆检测 (YOLOv8s)'
},
'illegal_parking_detection': {
'path': os.path.join(base_dir, 'models', 'vehicle_detection_paddle', 'mot_ppyoloe_l_36e_ppvehicle', 'model.pdmodel'),
'type': 'paddle',
'classes': ['vehicle'],
'labels': {'vehicle': ''},
'size': '200MB',
'description': '基于PaddlePaddle PP-YOLOE-l的违停检测模型,支持车牌识别',
'name': '违停检测 (Paddle)'
'path': os.path.join(base_dir, 'models', 'vehicle_detection_paddle', 'yolov8s.pt'),
'type': 'yolov8',
'classes': ['car', 'truck', 'bus', 'motorcycle'],
'labels': {'car': '小汽车', 'truck': '卡车', 'bus': '公交车', 'motorcycle': '摩托'},
'size': '23MB',
'description': '基于YOLOv8s的园区违停检测模型,支持停车时长与区域判定',
'name': '违停检测 (YOLOv8s)'
},
'fight_detection': {
'path': os.path.join(base_dir, 'models', 'fight_detection', 'yolov8n.pt'),
@@ -157,6 +157,12 @@ class ModelService:
os.path.exists(os.path.join(model_dir, f))
for f in required_files
)
elif config['type'] in ('yolov8', 'yolov10'):
# 本地路径存在,或官方预训练模型名(会自动下载)
model_exists = os.path.exists(model_path)
if not model_exists:
model_name = os.path.basename(model_path)
model_exists = model_name.startswith(('yolov8', 'yolov10', 'yolo11', 'yolo26'))
else:
model_exists = os.path.exists(model_path)
@@ -213,10 +219,6 @@ class ModelService:
from .paddle_detection_service import SmokingDetectionModel
logger.info(f"正在加载 PaddlePaddle 抽烟检测服务: {model_id}")
model = SmokingDetectionModel()
elif model_id in ['vehicle_detection', 'illegal_parking_detection']:
from .vehicle_detection_service import VehicleDetectionModel
logger.info(f"正在加载 PaddlePaddle 车辆检测服务: {model_id}")
model = VehicleDetectionModel()
else:
logger.error(f"未知的 Paddle 模型类型: {model_id}")
return None
@@ -230,14 +232,21 @@ class ModelService:
# 处理 YOLO 模型
model_path = config['path']
if not os.path.exists(model_path):
model_name = os.path.basename(model_path)
is_official_model = model_name.startswith(('yolov8', 'yolov10', 'yolo11', 'yolo26'))
if not os.path.exists(model_path) and not is_official_model:
logger.warning(f"模型文件不存在: {model_path},跳过加载 {model_id}")
return None
try:
logger.info(f"正在加载 YOLO 模型: {model_id} from {model_path}")
model = YOLO(model_path)
# 对违停检测模型,包装以支持 detect_illegal_parking 方法
if model_id == 'illegal_parking_detection':
from .vehicle_detection_service import VehicleDetectionModel
model = VehicleDetectionModel(yolo_model=model)
self.models[model_id] = model
logger.info(f"YOLO 模型加载成功: {model_id}")