This commit is contained in:
mshe 2025-09-27 18:04:08 +08:00
parent e4145a78b3
commit 1d3880e1fd
2 changed files with 31 additions and 33 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -1,7 +1,7 @@
from ultralytics import YOLO
import torch
# 加载预训练模型
# model = YOLO('models/yolov8n-pose.pt')
model = YOLO('models/yolov8n-pose.pt')
# model = YOLO('models/yolo11x-pose.pt')
# model = YOLO('models/yolov8n-pose.pt')
# model = YOLO('runs/pose/train2/weights/last.pt')
@ -22,38 +22,36 @@ import torch
# save_period: 每隔多少轮保存一次模型
# save_dir: 训练结果保存路径
# weights: 预训练模型路径
# model.info()
# model.train(data='./dataset1/train.yaml', epochs=300, imgsz=640, batch=32, device='cpu')
model.info()
model.train(data='./dataset1/train.yaml', epochs=300, imgsz=640, batch=32, device=0)
# 检查MPS可用性
print(f"MPS available: {torch.backends.mps.is_available()}")
print(f"MPS built: {torch.backends.mps.is_built()}")
model = YOLO('models/yolov8n-pose.pt')
# MPS优化配置
model.train(
data='./dataset1/train.yaml',
epochs=300,
imgsz=320, # M2 Pro上建议减小尺寸
batch=8, # 根据内存调整
device='mps', # 使用Apple Metal Performance Shaders
workers=2, # MPS下建议2个worker
patience=50,
lr0=0.01,
lrf=0.01,
momentum=0.9, # MPS上动量稍小
weight_decay=0.0005,
warmup_epochs=5.0,
box=7.5,
pose=1.0, # 增加姿态损失权重
kobj=1.5,
save=True,
exist_ok=True,
verbose=True,
amp=False # MPS上关闭自动混合精度
)
print("训练完成")
#
# # 检查MPS可用性
# print(f"MPS available: {torch.backends.mps.is_available()}")
# print(f"MPS built: {torch.backends.mps.is_built()}")
#
# model = YOLO('models/yolov8n-pose.pt')
#
# # MPS优化配置
# model.train( data='./dataset1/train.yaml', epochs=300,
# imgsz=320, # M2 Pro上建议减小尺寸
# batch=8, # 根据内存调整
# device='mps', # 使用Apple Metal Performance Shaders
# workers=2, # MPS下建议2个worker
# patience=50,
# lr0=0.01,
# lrf=0.01,
# momentum=0.9, # MPS上动量稍小
# weight_decay=0.0005,
# warmup_epochs=5.0,
# box=7.5,
# pose=1.0, # 增加姿态损失权重
# kobj=1.5,
# save=True,
# exist_ok=True,
# verbose=True,
# amp=False # MPS上关闭自动混合精度
# )
# print("训练完成")