1 yolo 训练
1.1修改自己的数据集合
我是有3个类别,差不多这么些数据
1.2 训练
from ultralytics import YOLO
# Load a model
model = YOLO("yolov8m.yaml") # build a new model from scratch
#model = YOLO('E:/pythonCode/pythonProject1/runs/detect/train/weights/last.pt')
results = model.train(data="./PCB/gesture2.yaml", epochs=2000, imgsz=640, device=[0], batch=4, workers=0, amp=False) # train the model
# results = model.train(data="pcb.yaml", epochs=20000,imgsz=640, device=[0], batch=4, workers=0) # train the model
metrics = model.val() # evaluate model performance on the validation set
# results = model("https://ultralytics.com/images/bus.jpg") # predict on an image
# path = model.export(format="onnx") # export the model to ONNX format
1660ti 显卡训练一晚上
第二天早上
训练的还不错。
2 .pt 转.onnx
from ultralytics import YOLO# Load a model
model = YOLO('./runs/detect/train6/weights/last.pt')
# Export the model
model.export(format='onnx', dynamic=True, opset=12) # 第2、3个参数禁止修改
3 .onnx 转.trt
在 TensorRT\bin 目录(如:I:\local\TensorRT-8.4.2.4\bin )下,运行
trtexec.exe --onnx=yolov8m_pcb.onnx --saveEngine=yolov8m_pcb2.trt --buildOnly --minShapes=images:1x3x640x640 --optShapes=images:4x3x640x640 --maxShapes=images:8x3x640x640