Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mindnlp/ultralytics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .models.model import YOLO

__all__ = ["YOLO"]
101 changes: 101 additions & 0 deletions src/mindnlp/ultralytics/cfg/datasets/coco128-seg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Ultralytics AGPL-3.0 License - https://ultralytics.com/license

# COCO128-seg dataset https://www.kaggle.com/datasets/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics
# Documentation: https://docs.ultralytics.com/datasets/segment/coco/
# Example usage: yolo train data=coco128-seg.yaml
# parent
# ├── ultralytics
# └── datasets
# └── coco128-seg ← downloads here (7 MB)

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ./datasets/coco128-seg # dataset root dir
train: images/train2017 # train images (relative to 'path') 128 images
val: images/train2017 # val images (relative to 'path') 128 images
test: # test images (optional)

# Classes
names:
0: person
1: bicycle
2: car
3: motorcycle
4: airplane
5: bus
6: train
7: truck
8: boat
9: traffic light
10: fire hydrant
11: stop sign
12: parking meter
13: bench
14: bird
15: cat
16: dog
17: horse
18: sheep
19: cow
20: elephant
21: bear
22: zebra
23: giraffe
24: backpack
25: umbrella
26: handbag
27: tie
28: suitcase
29: frisbee
30: skis
31: snowboard
32: sports ball
33: kite
34: baseball bat
35: baseball glove
36: skateboard
37: surfboard
38: tennis racket
39: bottle
40: wine glass
41: cup
42: fork
43: knife
44: spoon
45: bowl
46: banana
47: apple
48: sandwich
49: orange
50: broccoli
51: carrot
52: hot dog
53: pizza
54: donut
55: cake
56: chair
57: couch
58: potted plant
59: bed
60: dining table
61: toilet
62: tv
63: laptop
64: mouse
65: remote
66: keyboard
67: cell phone
68: microwave
69: oven
70: toaster
71: sink
72: refrigerator
73: book
74: clock
75: vase
76: scissors
77: teddy bear
78: hair drier
79: toothbrush

# Download script/URL (optional)
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/coco128-seg.zip
101 changes: 101 additions & 0 deletions src/mindnlp/ultralytics/cfg/datasets/coco128.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Ultralytics AGPL-3.0 License - https://ultralytics.com/license

# COCO128 dataset https://www.kaggle.com/datasets/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics
# Documentation: https://docs.ultralytics.com/datasets/detect/coco/
# Example usage: yolo train data=coco128.yaml
# parent
# ├── ultralytics
# └── datasets
# └── coco128 ← downloads here (7 MB)

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ./datasets/coco128 # dataset root dir
train: images/train2017 # train images (relative to 'path') 128 images
val: images/train2017 # val images (relative to 'path') 128 images
test: # test images (optional)

# Classes
names:
0: person
1: bicycle
2: car
3: motorcycle
4: airplane
5: bus
6: train
7: truck
8: boat
9: traffic light
10: fire hydrant
11: stop sign
12: parking meter
13: bench
14: bird
15: cat
16: dog
17: horse
18: sheep
19: cow
20: elephant
21: bear
22: zebra
23: giraffe
24: backpack
25: umbrella
26: handbag
27: tie
28: suitcase
29: frisbee
30: skis
31: snowboard
32: sports ball
33: kite
34: baseball bat
35: baseball glove
36: skateboard
37: surfboard
38: tennis racket
39: bottle
40: wine glass
41: cup
42: fork
43: knife
44: spoon
45: bowl
46: banana
47: apple
48: sandwich
49: orange
50: broccoli
51: carrot
52: hot dog
53: pizza
54: donut
55: cake
56: chair
57: couch
58: potted plant
59: bed
60: dining table
61: toilet
62: tv
63: laptop
64: mouse
65: remote
66: keyboard
67: cell phone
68: microwave
69: oven
70: toaster
71: sink
72: refrigerator
73: book
74: clock
75: vase
76: scissors
77: teddy bear
78: hair drier
79: toothbrush

# Download script/URL (optional)
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/coco128.zip
47 changes: 47 additions & 0 deletions src/mindnlp/ultralytics/cfg/datasets/coco8-pose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Ultralytics AGPL-3.0 License - https://ultralytics.com/license

# COCO8-pose dataset (first 8 images from COCO train2017) by Ultralytics
# Documentation: https://docs.ultralytics.com/datasets/pose/coco8-pose/
# Example usage: yolo train data=coco8-pose.yaml
# parent
# ├── ultralytics
# └── datasets
# └── coco8-pose ← downloads here (1 MB)

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ./datasets/coco8-pose # dataset root dir
train: images/train # train images (relative to 'path') 4 images
val: images/val # val images (relative to 'path') 4 images
test: # test images (optional)

# Keypoints
kpt_shape: [17, 3] # number of keypoints, number of dims (2 for x,y or 3 for x,y,visible)
flip_idx: [0, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15]

# Classes
names:
0: person

# Keypoint names per class
kpt_names:
0:
- nose
- left_eye
- right_eye
- left_ear
- right_ear
- left_shoulder
- right_shoulder
- left_elbow
- right_elbow
- left_wrist
- right_wrist
- left_hip
- right_hip
- left_knee
- right_knee
- left_ankle
- right_ankle

# Download script/URL (optional)
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/coco8-pose.zip
28 changes: 28 additions & 0 deletions src/mindnlp/ultralytics/cfg/datasets/imagenette2-160.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Ultralytics AGPL-3.0 License - https://ultralytics.com/license
# Imagenette2-160 Dataset by fast.ai
# Example usage: python train.py --data imagenette2-160.yaml

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ./datasets/imagenette2-160 # 你的数据集根目录 (根据你的截图和运行路径调整)
train: train # 训练集相对路径 (会与 path 拼接)
val: val # 验证集相对路径 (会与 path 拼接)
test: # 测试集 (Imagenette 没有单独的 test,可以留空)

# Classes
nc: 10 # 类别数量
names:
0: tench # 丁鱼
1: English springer # 英国斯宾格犬
2: cassette player # 录音机
3: chain saw # 链锯
4: church # 教堂
5: French horn # 圆号
6: garbage truck # 垃圾车
7: gas pump # 加油泵
8: golf ball # 高尔夫球
9: parachute # 降落伞

# Download script/URL (optional)
download: |
wget https://s3.amazonaws.com/fast-ai-imageclas/imagenette2-160.tgz
tar -xzvf imagenette2-160.tgz
60 changes: 60 additions & 0 deletions src/mindnlp/ultralytics/cfg/hyp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# ==========================================
# YOLO11 统一超参数配置 (适用于 Classify, Detect, Segment, Pose)
# ==========================================

# 1. 优化器与学习率 (Optimizer & LR)

optimizer: 'SGD' # 优化器选择
lr0: 0.01 # 初始学习率(微调pose任务,使用coco8-pose数据集时,推荐使用0.001)
lrf: 0.01 # 最终学习率比例 (lr0 * lrf = 0.0001)
momentum: 0.937 # 动量 (SGD momentum / Adam beta1)
weight_decay: 0.0005 # 权重衰减系数 (L2 正则化)
warmup_epochs: 3.0 # 预热轮数 (前几个 Epoch 学习率从低爬升)
warmup_momentum: 0.8 # 预热阶段的初始动量
warmup_bias_lr: 0.1 # 预热阶段偏置项(bias)的学习率


# 2. 任务损失权重 (Loss Weights)
# 说明:各个任务会自动读取自己需要的权重,无关的会被忽略

box: 7.5 # 边界框回归损失 (GIoU/CIoU)
cls: 0.5 # 类别分类损失 (BCE / CE)
dfl: 1.5 # 分布焦点损失 (DFL)
pose: 12.0 # 姿态估计:关键点坐标损失
kobj: 1.0 # 姿态估计:关键点可见度损失
seg: 2.5 # 实例分割:掩码 BCE 损失
label_smoothing: 0.0 # 标签平滑系数 (防止过拟合,通常为0)


# 3. 基础数据增强 (Data Augmentation)

hsv_h: 0.015 # 图像 HSV 色调增强比例
hsv_s: 0.7 # 图像 HSV 饱和度增强比例
hsv_v: 0.4 # 图像 HSV 明度增强比例
degrees: 0.0 # 图像旋转角度 (+/- deg)
translate: 0.1 # 图像平移比例 (+/- fraction)
scale: 0.5 # 图像缩放比例 (+/- gain)
shear: 0.0 # 图像剪切角度 (+/- deg)
perspective: 0.0 # 透视变换系数 (0-0.001)
flipud: 0.0 # 图像上下翻转概率
fliplr: 0.5 # 图像左右翻转概率 (分类和检测常用)


# 4. 高级图像拼接增强 (Mosaic & MixUp)
# 注意:分类任务通常不使用马赛克增强,代码里需做判断

mosaic: 1.0 # 马赛克数据增强概率 (检测/分割/姿态 核心)
mixup: 0.0 # MixUp 增强概率
copy_paste: 0.0 # Copy-Paste 分割增强概率


# 5. 验证与推理超参数 (Val & Inference Settings)
# 注意:在验证(Val)计算 mAP 时,系统会自动将 conf 降为 0.001;
# 下面填写的 conf 主要供常规推理(Predict)或最终展示使用。

conf: 0.25 # 目标置信度阈值 (预测时使用 0.25,验证算 mAP 时代码内部会强转为 0.001)
iou: 0.6 # NMS (非极大值抑制) 的 IoU 阈值
max_det: 300 # 每张图像最多保留的预测框数量
half: False # 是否使用 FP16 半精度推理 (Ascend/GPU 推荐开启以提速)
dnn: False # 是否使用 OpenCV DNN 进行 ONNX 推理
plots: True # 是否在验证期间保存画好框的结果图和各种评估图表
33 changes: 33 additions & 0 deletions src/mindnlp/ultralytics/cfg/models/11/yolo11-cls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

# Ultralytics YOLO11-cls image classification model
# Model docs: https://docs.ultralytics.com/models/yolo11
# Task docs: https://docs.ultralytics.com/tasks/classify

# Parameters
nc: 1000 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolo11n-cls.yaml' will call yolo11-cls.yaml with scale 'n'
# [depth, width, max_channels]
n: [0.50, 0.25, 1024] # summary: 86 layers, 1633584 parameters, 1633584 gradients, 0.5 GFLOPs
s: [0.50, 0.50, 1024] # summary: 86 layers, 5545488 parameters, 5545488 gradients, 1.6 GFLOPs
m: [0.50, 1.00, 512] # summary: 106 layers, 10455696 parameters, 10455696 gradients, 5.0 GFLOPs
l: [1.00, 1.00, 512] # summary: 176 layers, 12937104 parameters, 12937104 gradients, 6.2 GFLOPs
x: [1.00, 1.50, 512] # summary: 176 layers, 28458544 parameters, 28458544 gradients, 13.7 GFLOPs

# YOLO11n backbone
backbone:
# [from, repeats, module, args]
- [-1, 1, Conv, [64, 3, 2]] # 0-P1/2
- [-1, 1, Conv, [128, 3, 2]] # 1-P2/4
- [-1, 2, C3k2, [256, False, 0.25]]
- [-1, 1, Conv, [256, 3, 2]] # 3-P3/8
- [-1, 2, C3k2, [512, False, 0.25]]
- [-1, 1, Conv, [512, 3, 2]] # 5-P4/16
- [-1, 2, C3k2, [512, True]]
- [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32
- [-1, 2, C3k2, [1024, True]]
- [-1, 2, C2PSA, [1024]] # 9

# YOLO11n head
head:
- [-1, 1, Classify, [nc]] # Classify
Loading