工程车挖掘机3027-5类 挖掘机检测数据集 混凝土搅拌车 倾倒 倾卸卡车
1 在这里插入图片描述
1
1
1 
挖掘机 混凝土搅拌车 倾倒 倾卸卡车 标签
一、数据集信息表
| 数据集名称 | 工程车&挖掘机检测数据集 |
| 任务类型 | 目标检测 |
| 图片总量 | 3027 张 |
| 类别数量 | 5 类 |
| 检测类别 | 挖掘机、混凝土搅拌车、倾卸卡车、车辆倾倒、车辆倾卸 |
| 适用场景 | 工地工程车辆识别、作业状态检测、安防监控 |
| 推荐标注格式 | YOLO 标准格式(txt归一化坐标) |
类别ID映射(固定对应,训练/推理统一使用) 0: 挖掘机 1: 混凝土搅拌车 2: 倾卸卡车 3: 倾倒 4: 倾卸
二、环境依赖安装
pip install torch torchvision ultralytics opencv-python numpy tqdm
三、数据集目录结构(YOLO 标准)
construction_vehicle/
├── train/
│ ├── images/ # 训练集图片
│ └── labels/ # 训练集标注txt
├── val/
│ ├── images/ # 验证集图片
│ └── labels/ # 验证集标注txt
└── vehicle.yaml # 数据集配置文件
四、数据集配置文件 vehicle.yaml
path: ./construction_vehicle
train: train/images
val: val/images
nc: 5
names:
0: 挖掘机
1: 混凝土搅拌车
2: 倾卸卡车
3: 倾倒
4: 倾卸
五、训练代码 train_vehicle.py
针对工地复杂背景、车辆姿态多变、作业状态检测做参数优化
from ultralytics import YOLO
def train_construction_vehicle():
# 选用 yolov8s 平衡精度与速度,边缘部署可换 yolov8n
model = YOLO("yolov8s.pt")
model.train(
data="./construction_vehicle/vehicle.yaml",
epochs=120,
imgsz=640,
batch=8,
device=0, # 无GPU改为 cpu
patience=20, # 早停防过拟合
mosaic=1.0,
hsv_h=0.015,
hsv_s=0.7,
hsv_v=0.5,
degrees=20, # 适配车辆不同拍摄角度
fliplr=0.5,
flipud=0.1,
perspective=0.001,
project="vehicle_run",
name="yolov8_vehicle_train",
exist_ok=True
)
print("工程车辆检测模型训练完成!")
if __name__ == "__main__":
train_construction_vehicle()
六、单图推理可视化 predict_single.py
from ultralytics import YOLO
import cv2
def detect_vehicle(img_path, weight_path):
model = YOLO(weight_path)
# 置信度0.25,兼顾小目标与作业状态漏检
results = model(img_path, conf=0.25, iou=0.45)
for res in results:
img_show = res.plot()
cv2.imshow("Construction Vehicle Detect", img_show)
# 打印检测结果
for box in res.boxes:
cls_id = int(box.cls)
conf = float(box.conf)
print(f"类别ID:{cls_id} 置信度:{conf:.2f}")
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == "__main__":
detect_vehicle(
img_path="./construction_vehicle/val/images/test.jpg",
weight_path="./vehicle_run/yolov8_vehicle_train/weights/best.pt"
)
七、批量推理代码 batch_predict.py
批量处理图片并保存检测结果
import os
from ultralytics import YOLO
def batch_detect(img_dir, weight_path, save_dir):
os.makedirs(save_dir, exist_ok=True)
model = YOLO(weight_path)
suffix = (".jpg", ".png", ".jpeg")
for name in os.listdir(img_dir):
if name.lower().endswith(suffix):
img_path = os.path.join(img_dir, name)
res = model(img_path, conf=0.25)
res[0].save(os.path.join(save_dir, name))
print(f"批量检测完成,结果已保存至 {save_dir}")
if __name__ == "__main__":
batch_detect(
img_dir="./construction_vehicle/val/images",
weight_path="./vehicle_run/yolov8_vehicle_train/weights/best.pt",
save_dir="./construction_vehicle/predict_result"
)
八、模型导出(边缘部署 ONNX)
from ultralytics import YOLO
model = YOLO("./vehicle_run/yolov8_vehicle_train/weights/best.pt")
model.export(format="onnx", imgsz=640)
print("ONNX 模型导出完成,可用于监控、嵌入式设备部署")
九、使用说明&调优建议
数据划分 3027张样本量充足,建议按 训练集80%、验证集20% 划分,保证5个类别样本分布均衡。
场景适配 工地光照变化大、杂物遮挡多,代码已开启色彩、旋转增强;若遮挡严重,可适当调高 copy_paste 增强。
类别区分要点
- 挖掘机、搅拌车、倾卸卡车:属于车辆本体检测;
- 倾倒、倾卸:属于作业状态检测,目标形态多变,推理置信度不宜设置过高。
- 显存不足:将 batch 改为 4 / 2;
- 前端实时监控部署:训练时改用 yolov8n 轻量化模型。


