尺寸标注识别5 实例分割 roboflow | result.boxes获取边界框 | yolov8n-seg架构 torchinfo | 对直线关系不敏感
https://gitee.com/njsgcs/yolo-local
单标注一个尺寸线
100轮就百分百了
Sign in to Roboflow
有混起来的问题
roboflow训练用的cocon-seg模型我网上找不到
上面这种比较麻烦
text的中心要在dt范围内
屏幕点以下等同于按下save(enter)
取最长线段作为dt的长度
按下drag tool中键可以移动,左键也可以
{"predictions": [{"x": 184,"y": 91.5,"width": 28,"height": 15,"confidence": 0.917,"class": "text","points": [{"x": 170.5,"y": 84.711},{"x": 170.5,"y": 99.248},{"x": 197.78,"y": 99.248},{"x": 197.78,"y": 84.711}],"class_id": 1,"detection_id": "8521534d-0755-4bd3-aea0-090637b5a3a4"},{"x": 286.5,"y": 163.5,"width": 27,"height": 15,"confidence": 0.881,"class": "text","points": [{"x": 273.42,"y": 155.889},{"x": 273.42,"y": 170.425},{"x": 292.64,"y": 170.425},{"x": 293.26,"y": 169.924},{"x": 294.5,"y": 169.924},{"x": 295.12,"y": 170.425},{"x": 298.22,"y": 170.425},{"x": 299.46,"y": 169.423},{"x": 299.46,"y": 155.889}],"class_id": 1,"detection_id": "b512339a-77d5-4b44-a63f-f0465cfd5a84"},{"x": 286,"y": 319.5,"width": 20,"height": 13,"confidence": 0.817,"class": "text","points": [{"x": 275.9,"y": 313.783},{"x": 275.9,"y": 326.314},{"x": 295.74,"y": 326.314},{"x": 295.74,"y": 313.783}],"class_id": 1,"detection_id": "84de0494-8e1c-4f1e-98d2-371acbe967bf"},{"x": 362.5,"y": 268,"width": 27,"height": 14,"confidence": 0.815,"class": "text","points": [{"x": 349.68,"y": 261.151},{"x": 349.68,"y": 274.685},{"x": 375.1,"y": 274.685},{"x": 375.1,"y": 261.151}],"class_id": 1,"detection_id": "29c6d5a3-5c5c-4a2e-af99-66d53875030c"},{"x": 152,"y": 266.5,"width": 20,"height": 15,"confidence": 0.809,"class": "text","points": [{"x": 143.22,"y": 259.648},{"x": 143.22,"y": 260.149},{"x": 142.6,"y": 260.65},{"x": 142.6,"y": 272.179},{"x": 143.22,"y": 272.179},{"x": 143.84,"y": 272.68},{"x": 146.32,"y": 272.68},{"x": 146.94,"y": 273.181},{"x": 157.48,"y": 273.181},{"x": 158.1,"y": 272.68},{"x": 158.1,"y": 271.176},{"x": 158.72,"y": 270.675},{"x": 158.72,"y": 269.673},{"x": 159.96,"y": 268.67},{"x": 161.82,"y": 268.67},{"x": 161.82,"y": 260.149},{"x": 161.2,"y": 259.648}],"class_id": 1,"detection_id": "abdabdf3-2e20-4f64-be9f-c6d741f0dd15"},{"x": 286.5,"y": 163.5,"width": 7,"height": 85,"confidence": 0.688,"class": "dt","points": [{"x": 283.34,"y": 120.801},{"x": 283.34,"y": 206.014},{"x": 289.54,"y": 206.014},{"x": 289.54,"y": 120.801}],"class_id": 0,"detection_id": "5ee057ba-a8fa-438a-af2a-238b327efa9b"},{"x": 363.5,"y": 268,"width": 53,"height": 6,"confidence": 0.675,"class": "dt","points": [{"x": 337.28,"y": 265.663},{"x": 337.28,"y": 270.675},{"x": 360.22,"y": 270.675},{"x": 360.84,"y": 270.174},{"x": 372.62,"y": 270.174},{"x": 373.24,"y": 270.675},{"x": 388.12,"y": 270.675},{"x": 389.36,"y": 269.673},{"x": 389.36,"y": 265.663}],"class_id": 0,"detection_id": "0fa3e6b6-df95-490b-ac40-02f1be87ed97"},{"x": 286.5,"y": 318.5,"width": 7,"height": 37,"confidence": 0.663,"class": "dt","points": [{"x": 283.34,"y": 300.249},{"x": 283.34,"y": 336.84},{"x": 289.54,"y": 336.84},{"x": 289.54,"y": 300.249}],"class_id": 0,"detection_id": "86198722-579d-4f07-a285-acf774afddc2"},{"x": 186,"y": 92.5,"width": 146,"height": 7,"confidence": 0.62,"class": "dt","points": [{"x": 114.08,"y": 89.223},{"x": 114.08,"y": 95.739},{"x": 170.5,"y": 95.739},{"x": 171.12,"y": 95.238},{"x": 180.42,"y": 95.238},{"x": 181.04,"y": 95.739},{"x": 256.68,"y": 95.739},{"x": 257.92,"y": 94.736},{"x": 257.92,"y": 89.223},{"x": 204.6,"y": 89.223},{"x": 203.98,"y": 89.724},{"x": 194.06,"y": 89.724},{"x": 193.44,"y": 89.223}],"class_id": 0,"detection_id": "e10c9e2a-415d-44c5-a6eb-1981e7f71aa7"},{"x": 152.5,"y": 265,"width": 19,"height": 6,"confidence": 0.552,"class": "dt","points": [{"x": 143.22,"y": 264.66},{"x": 143.22,"y": 268.169},{"x": 159.96,"y": 268.169},{"x": 160.58,"y": 267.668},{"x": 161.82,"y": 267.668},{"x": 161.82,"y": 265.161},{"x": 161.2,"y": 265.161},{"x": 160.58,"y": 264.66}],"class_id": 0,"detection_id": "f02982c1-fa5d-466c-b7fb-d1701a51543f"}]
}
大部分问题不大
缺少交叉标注训练集
这块确实难识别
我需要一个带关键点检测或者关键线检测的实例分割模型
from ultralytics import YOLO
import cv2# 加载模型
model = YOLO('runs/segment/train6/weights/best.pt')# 评估模型性能(可选)
metrics = model.predict(task='segment')# 执行图像上的目标检测
results = model("datasets/Drawing Annotation Recognition8.v1i.yolov12/valid/images/""Snipaste_2025-07-12_15-08-24_png.rf.0931b009a94871a6be21f7572200f9f7.jpg", task='segment')# 遍历结果并绘制
for result in results:# 获取分割掩码masks = result.masksif masks is not None:print("Segmentation Masks:", masks)# 绘制检测结果annotated_frame = result.plot() # 使用plot方法绘制结果# 显示图像cv2.imshow('Detection Result', annotated_frame)cv2.waitKey(0) # 按任意键关闭窗口cv2.destroyAllWindows()
画出几何中心
result.boxes可以获取边界框
from ultralytics import YOLO
import cv2# 加载模型
model = YOLO('runs/segment/train6/weights/best.pt')# 图像路径
img_path = "datasets/Drawing Annotation Recognition8.v1i.yolov12/valid/images/" \"Snipaste_2025-07-12_15-08-24_png.rf.0931b009a94871a6be21f7572200f9f7.jpg"# 推理
results = model(img_path, task='segment')# 读取原始图像
im0 = cv2.imread(img_path)for result in results:# 获取边界框boxes = result.boxes.xyxy # [x1, y1, x2, y2]for box in boxes:x1, y1, x2, y2 = map(int, box)center_x = (x1 + x2) // 2center_y = (y1 + y2) // 2# 绘制边界框cv2.rectangle(im0, (x1, y1), (x2, y2), (0, 255, 0), 2)# 绘制中心点cv2.circle(im0, (center_x, center_y), 5, (0, 0, 255), -1) # 红色实心圆点# 或者使用分割掩码计算质心if result.masks is not None:for mask in result.masks.xy:# 计算掩码的最小外接矩形x, y, w, h = cv2.boundingRect(mask.astype(int))center_x = x + w // 2center_y = y + h // 2cv2.circle(im0, (center_x, center_y), 5, (255, 0, 0), -1) # 蓝色实心圆点# 显示或保存图像
cv2.imshow('Detection with Center', im0)
cv2.waitKey(0)
cv2.destroyAllWindows()
# cv2.imwrite('output_with_center.jpg', im0)
SegmentationModel((model): Sequential((0): Conv((conv): Conv2d(3, 16, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)(bn): BatchNorm2d(16, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(1): Conv((conv): Conv2d(16, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(2): C2f((cv1): Conv((conv): Conv2d(32, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(48, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(m): ModuleList((0): Bottleneck((cv1): Conv((conv): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(16, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(16, 16, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(16, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True)))))(3): Conv((conv): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(4): C2f((cv1): Conv((conv): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(128, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(m): ModuleList((0-1): 2 x Bottleneck((cv1): Conv((conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True)))))(5): Conv((conv): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(6): C2f((cv1): Conv((conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(m): ModuleList((0-1): 2 x Bottleneck((cv1): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True)))))(7): Conv((conv): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(8): C2f((cv1): Conv((conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(384, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(m): ModuleList((0): Bottleneck((cv1): Conv((conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True)))))(9): SPPF((cv1): Conv((conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(m): MaxPool2d(kernel_size=5, stride=1, padding=2, dilation=1, ceil_mode=False))(10): Upsample(scale_factor=2.0, mode='nearest')(11): Concat()(12): C2f((cv1): Conv((conv): Conv2d(384, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(192, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(m): ModuleList((0): Bottleneck((cv1): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True)))))(13): Upsample(scale_factor=2.0, mode='nearest')(14): Concat()(15): C2f((cv1): Conv((conv): Conv2d(192, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(96, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(m): ModuleList((0): Bottleneck((cv1): Conv((conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True)))))(16): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(17): Concat()(18): C2f((cv1): Conv((conv): Conv2d(192, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(192, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(m): ModuleList((0): Bottleneck((cv1): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True)))))(19): Conv((conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(20): Concat()(21): C2f((cv1): Conv((conv): Conv2d(384, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(384, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(256, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(m): ModuleList((0): Bottleneck((cv1): Conv((conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv2): Conv((conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(128, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True)))))(22): Segment((cv2): ModuleList((0): Sequential((0): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(1): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(2): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1)))(1): Sequential((0): Conv((conv): Conv2d(128, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(1): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(2): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1)))(2): Sequential((0): Conv((conv): Conv2d(256, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(1): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(2): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1))))(cv3): ModuleList((0): Sequential((0): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(1): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(2): Conv2d(64, 2, kernel_size=(1, 1), stride=(1, 1)))(1): Sequential((0): Conv((conv): Conv2d(128, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(1): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(2): Conv2d(64, 2, kernel_size=(1, 1), stride=(1, 1)))(2): Sequential((0): Conv((conv): Conv2d(256, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(1): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(2): Conv2d(64, 2, kernel_size=(1, 1), stride=(1, 1))))(dfl): DFL((conv): Conv2d(16, 1, kernel_size=(1, 1), stride=(1, 1), bias=False))(proto): Proto((cv1): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(upsample): ConvTranspose2d(64, 64, kernel_size=(2, 2), stride=(2, 2))(cv2): Conv((conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(64, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(cv3): Conv((conv): Conv2d(64, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True)))(cv4): ModuleList((0): Sequential((0): Conv((conv): Conv2d(64, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(1): Conv((conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(2): Conv2d(32, 32, kernel_size=(1, 1), stride=(1, 1)))(1): Sequential((0): Conv((conv): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(1): Conv((conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(2): Conv2d(32, 32, kernel_size=(1, 1), stride=(1, 1)))(2): Sequential((0): Conv((conv): Conv2d(256, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(1): Conv((conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)(bn): BatchNorm2d(32, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)(act): SiLU(inplace=True))(2): Conv2d(32, 32, kernel_size=(1, 1), stride=(1, 1))))))
)
====================================================================================================
Layer (type:depth-idx) Output Shape Param #
====================================================================================================
SegmentationModel [1, 38, 8400] --
├─Sequential: 1-1 -- --
│ └─Conv: 2-1 [1, 16, 320, 320] --
│ │ └─Conv2d: 3-1 [1, 16, 320, 320] (432)
│ │ └─BatchNorm2d: 3-2 [1, 16, 320, 320] (32)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Conv: 2-3 [1, 32, 160, 160] --
│ │ └─Conv2d: 3-4 [1, 32, 160, 160] (4,608)
│ │ └─BatchNorm2d: 3-5 [1, 32, 160, 160] (64)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-5 [1, 32, 160, 160] 6,272
│ │ └─Conv: 3-7 [1, 32, 160, 160] (1,088)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-11 -- (recursive)
│ │ └─ModuleList: 3-11 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-11 -- (recursive)
│ │ └─ModuleList: 3-11 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-11 -- (recursive)
│ │ └─Conv: 3-13 [1, 32, 160, 160] (1,600)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Conv: 2-13 [1, 64, 80, 80] --
│ │ └─Conv2d: 3-15 [1, 64, 80, 80] (18,432)
│ │ └─BatchNorm2d: 3-16 [1, 64, 80, 80] (128)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-15 [1, 64, 80, 80] 45,440
│ │ └─Conv: 3-18 [1, 64, 80, 80] (4,224)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-25 -- (recursive)
│ │ └─ModuleList: 3-26 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-25 -- (recursive)
│ │ └─ModuleList: 3-26 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-25 -- (recursive)
│ │ └─ModuleList: 3-26 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-25 -- (recursive)
│ │ └─ModuleList: 3-26 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-25 -- (recursive)
│ │ └─Conv: 3-28 [1, 64, 80, 80] (8,320)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Conv: 2-27 [1, 128, 40, 40] --
│ │ └─Conv2d: 3-30 [1, 128, 40, 40] (73,728)
│ │ └─BatchNorm2d: 3-31 [1, 128, 40, 40] (256)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-29 [1, 128, 40, 40] 180,992
│ │ └─Conv: 3-33 [1, 128, 40, 40] (16,640)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-39 -- (recursive)
│ │ └─ModuleList: 3-41 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-39 -- (recursive)
│ │ └─ModuleList: 3-41 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-39 -- (recursive)
│ │ └─ModuleList: 3-41 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-39 -- (recursive)
│ │ └─ModuleList: 3-41 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-39 -- (recursive)
│ │ └─Conv: 3-43 [1, 128, 40, 40] (33,024)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Conv: 2-41 [1, 256, 20, 20] --
│ │ └─Conv2d: 3-45 [1, 256, 20, 20] (294,912)
│ │ └─BatchNorm2d: 3-46 [1, 256, 20, 20] (512)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-43 [1, 256, 20, 20] 394,240
│ │ └─Conv: 3-48 [1, 256, 20, 20] (66,048)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-49 -- (recursive)
│ │ └─ModuleList: 3-52 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-49 -- (recursive)
│ │ └─ModuleList: 3-52 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-49 -- (recursive)
│ │ └─Conv: 3-54 [1, 256, 20, 20] (98,816)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─SPPF: 2-51 [1, 256, 20, 20] 131,584
│ │ └─Conv: 3-56 [1, 128, 20, 20] (33,024)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─SPPF: 2-53 -- (recursive)
│ │ └─MaxPool2d: 3-58 [1, 128, 20, 20] --
│ │ └─MaxPool2d: 3-59 [1, 128, 20, 20] --
│ │ └─MaxPool2d: 3-60 [1, 128, 20, 20] --
│ │ └─Conv: 3-61 [1, 256, 20, 20] (131,584)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Upsample: 2-55 [1, 256, 40, 40] --
│ └─Concat: 2-56 [1, 384, 40, 40] --
│ └─C2f: 2-57 [1, 128, 40, 40] 98,816
│ │ └─Conv: 3-63 [1, 128, 40, 40] (49,408)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-63 -- (recursive)
│ │ └─ModuleList: 3-67 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-63 -- (recursive)
│ │ └─ModuleList: 3-67 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-63 -- (recursive)
│ │ └─Conv: 3-69 [1, 128, 40, 40] (24,832)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Upsample: 2-65 [1, 128, 80, 80] --
│ └─Concat: 2-66 [1, 192, 80, 80] --
│ └─C2f: 2-67 [1, 64, 80, 80] 24,832
│ │ └─Conv: 3-71 [1, 64, 80, 80] (12,416)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-73 -- (recursive)
│ │ └─ModuleList: 3-75 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-73 -- (recursive)
│ │ └─ModuleList: 3-75 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-73 -- (recursive)
│ │ └─Conv: 3-77 [1, 64, 80, 80] (6,272)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Conv: 2-75 [1, 64, 40, 40] --
│ │ └─Conv2d: 3-79 [1, 64, 40, 40] (36,864)
│ │ └─BatchNorm2d: 3-80 [1, 64, 40, 40] (128)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Concat: 2-77 [1, 192, 40, 40] --
│ └─C2f: 2-78 [1, 128, 40, 40] 98,816
│ │ └─Conv: 3-82 [1, 128, 40, 40] (24,832)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-84 -- (recursive)
│ │ └─ModuleList: 3-86 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-84 -- (recursive)
│ │ └─ModuleList: 3-86 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-84 -- (recursive)
│ │ └─Conv: 3-88 [1, 128, 40, 40] (24,832)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Conv: 2-86 [1, 128, 20, 20] --
│ │ └─Conv2d: 3-90 [1, 128, 20, 20] (147,456)
│ │ └─BatchNorm2d: 3-91 [1, 128, 20, 20] (256)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Concat: 2-88 [1, 384, 20, 20] --
│ └─C2f: 2-89 [1, 256, 20, 20] 394,240
│ │ └─Conv: 3-93 [1, 256, 20, 20] (98,816)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-95 -- (recursive)
│ │ └─ModuleList: 3-97 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-95 -- (recursive)
│ │ └─ModuleList: 3-97 -- (recursive)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─C2f: 2-95 -- (recursive)
│ │ └─Conv: 3-99 [1, 256, 20, 20] (98,816)
│ └─Segment: 2-96 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ └─Segment: 2-97 [1, 38, 8400] --
│ │ └─Proto: 3-101 [1, 32, 160, 160] (92,544)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─Proto: 3-105 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─Proto: 3-105 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-131 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-131 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-131 -- (recursive)
│ │ └─ModuleList: 3-136 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-136 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-136 -- (recursive)
│ │ └─ModuleList: 3-131 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-131 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-131 -- (recursive)
│ │ └─ModuleList: 3-136 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-136 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-136 -- (recursive)
│ │ └─ModuleList: 3-131 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-131 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-131 -- (recursive)
│ │ └─ModuleList: 3-136 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-136 -- (recursive)
│ │ └─ModuleList: 3-135 -- (recursive)
│ │ └─ModuleList: 3-136 -- (recursive)
│ │ └─DFL: 3-137 [1, 4, 8400] (16)
====================================================================================================
Total params: 5,423,852
Trainable params: 0
Non-trainable params: 5,423,852
Total mult-adds (Units.GIGABYTES): 5.99
====================================================================================================
Input size (MB): 4.92
Forward/backward pass size (MB): 292.35
Params size (MB): 13.06
Estimated Total Size (MB): 310.32
====================================================================================================
from ultralytics import YOLO
import cv2
from torchinfo import summary#micromamba activate ./.venv
#tensorboard --logdir=runs
# 加载模型
model = YOLO('runs/segment/train6/weights/best.pt')summary(model.model, input_size=(1, 3, 640, 640))
# 图像路径
img_path = "datasets/Drawing Annotation Recognition8.v1i.yolov12/valid/images/" \"Snipaste_2025-07-12_15-08-24_png.rf.0931b009a94871a6be21f7572200f9f7.jpg"
# img_path = "datasets/Drawing Annotation Recognition8.v1i.yolov12/test/images/" \
# "Snipaste_2025-07-12_19-54-54_png.rf.a562ea098219605eff9cb4ce58f09d0e.jpg"# 推理
results = model(img_path, task='segment', conf=0.2)# 读取原始图像
im0 = cv2.imread(img_path)for result in results:# 获取边界框boxes = result.boxes.xyxy # [x1, y1, x2, y2]for box in boxes:x1, y1, x2, y2 = map(int, box)center_x = (x1 + x2) // 2center_y = (y1 + y2) // 2# 绘制边界框cv2.rectangle(im0, (x1, y1), (x2, y2), (0, 255, 0), 2)# 绘制中心点cv2.circle(im0, (center_x, center_y), 5, (0, 0, 255), -1) # 红色实心圆点# 显示或保存图像
cv2.imshow('Detection with Center', im0)
cv2.waitKey(0)
cv2.destroyAllWindows()
# cv2.imwrite('output_with_center.jpg', im0)
这个架构好像对直线关系不敏感
我怀疑是数据集不够大