训练代码如下:
from ultralytics import YOLO
model = YOLO(r"yolov12.yaml")
# Train the model
results = model.train(
data=r"/yolov12-main/data1/cls.yaml", # 自己数据集的类别
epochs=100,
batch=16,
imgsz=640,
scale=0.5, # S:0.9; M:0.9; L:0.9; X:0.9
mosaic=1.0,
mixup=0.0, # S:0.05; M:0.15; L:0.15; X:0.2
copy_paste=0.1, # S:0.15; M:0.4; L:0.5; X:0.6
device="0",
workers=8,
)
detect检测代码如下:
# -*- coding: utf-8 -*-
from ultralytics import YOLO
if __name__ == '__main__':
# Load a model
model = YOLO(model=r"/yolov12-main/runs/detect/train/weights/best.pt") # 训练好的权重
model.predict(source=r'/yolov12-main/detect1/images/', # 检测的图片路径
save=True,
workers=8, # 数据加载工作线程数
device=2, # 显卡编号
#imgsz=416, # (int) size of input images as integer or w,h
#conf=0.25, # object confidence threshold for detection (default 0.25 predict, 0.001 val)
#iou=0.6, # # intersection over union (IoU) threshold for NMS
show=False, # show results if possible
project='runs/detect', # (str, optional) project name
name='predict', # (str, optional) experiment name, results saved to 'project/name' directory
save_txt=True, # save results as .txt file
save_conf=True, # save results with confidence scores
save_crop=False, # save cropped images with results
show_labels=True, # show object labels in plots
show_conf=True, # show object confidence scores in plots
vid_stride=1, # video frame-rate stride
line_width=3, # bounding box thickness (pixels)
visualize=False, # visualize model features
augment=False, # apply image augmentation to prediction sources
agnostic_nms=False, # class-agnostic NMS
retina_masks=False, # use high-resolution segmentation masks
boxes=True, # Show boxes in segmentation predictions
)
模型计算量代码如下:
from ultralytics import YOLO
if __name__ == '__main__':
# Load a model
model = YOLO(r"/yolov12-main/ultralytics/cfg/models/v12/yolov12.yaml") # 这里放你的模型文件地址
model.info()
model = YOLO(r"/yolov12-main/ultralytics/cfg/models/11/yolo11.yaml") # 这里放你的模型文件地址
model.info()
model = YOLO(r"/yolov12-main/ultralytics/cfg/models/v10/yolov10n.yaml") # 这里放你的模型文件地址
model.info()
model = YOLO(r"/yolov12-main/ultralytics/cfg/models/v8/yolov8.yaml") # 这里放你的模型文件地址
model.info()