惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
Martin Fowler
Martin Fowler
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
B
Blog
U
Unit 42
B
Blog RSS Feed
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
腾讯CDC
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
博客园 - 聂微东
MyScale Blog
MyScale Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta

博客园 - 网络来者

Element Plus 多页面后台与 ASP.NET Core API 从零手敲教程 从零创建 MESTOOLS 消息弹窗跟练教程 uni app开发一个子页面 MES物料分摊 墨西哥 嘉兴 兼容车牌摄像头 和 tplink 摄像头的sdk开发包 集成 tplink摄像头监控 mes测试机 redis vue学习 vue 系统文件结构 udp server 监听服务 第一个服务 c# 开发相关 openclaw 安装 c# 版本号 oracle 触发器 脚本方式安装Python 特定版本 idea 激活 Chrome MCP Server mcp ok mcp_server RepositoryItemGridLookUpEdit 使用 ok devexpress gridcontrol表格知识 winfrom 弹文本框 松下贴片机解锁 Serilog日志组件使用 git 使用
训练数字识别模型
网络来者 · 2026-05-09 · via 博客园 - 网络来者
  • Ultralytics 8.4.48
  • Python 3.10.11
  • PyTorch 1.13.0+cu116
  • GPU: Quadro P620 (4096MiB)

https://www.python.org/ftp/python/3.10.11/python-3.10.11-amd64.exe

C:\Users\huangliangmou.SUPER\.local\bin>.\uv cache clean

pip install torch==1.13.0+cu116 torchvision==0.14.0+cu116 -f https://download.pytorch.org/whl/cu116/torch_stable.html

下载手写图片 

createnumber.py
import torchvision
from torchvision import transforms
import os
from PIL import Image

os.makedirs('images/train', exist_ok=True)
os.makedirs('labels/train', exist_ok=True)

transform=transforms.Compose([transforms.ToTensor()])
mnist=torchvision.datasets.MNIST(root='./data', train=True, download=True, transform=transform)

for i, (img, label) in enumerate(mnist):
    img=Image.fromarray((img.squeeze().numpy()*255).astype('uint8'))
    img_path=f'images/train/{i:06d}.jpg'
    img.save(img_path)
    # 标签:单个数字占满图,xywh归一化
    with open(f'labels/train/{i:06d}.txt', 'w') as f:
        f.write(f'{label} 0.5 0.5 1 1\n')

第一步:升级 pip(必须先做)

python -m pip install --upgrade pip

第二步:安装依赖

pip install wheel numpy opencv-python

第三步:安装 ultralytics

pip install ultralytics

pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple --timeout 100

pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple --ignore-installed PyYAML

再执行训练命令:

yolo train model=yolov8n.pt data=mnist.yaml epochs=50 imgsz=28

Python 代码直接训练   train.py

# 终极训练代码,直接运行!
import os
import sys
# 强制屏蔽坏的库
sys.modules['psutil'] = None

from ultralytics import YOLO

# 加载模型
model = YOLO("yolov8n.pt")

# 开始训练(你的数据集已经准备好了)
model.train(
    data="mnist.yaml",
    epochs=50,
    imgsz=28,
    device="cpu",  # 用CPU训练,最稳定
    verbose=True
)