当前位置: 首页 > news >正文

yolov8/yolov10 MLU370 实现推理/单多卡训练!

文章目录

  • 前言
  • 一、平台环境配置
  • 二、基础环境配置
    • 1.代码下载
    • 2.环境安装
    • 3.模型下载
    • 4.代码修改
  • 三.单卡推理
  • 四、单/多卡训练


前言

本章主要操作以yolov8为主,但是yolov10用该操作也能直接适用,开干!

一、平台环境配置

镜像选择:v24.06-torch2.3.0-catch1.21.0-ubuntu22.04-py310
驱动版本:HYG-2*370-5.10.29
存储卷记得挂载,已经有很多小伙伴根目录超限环境崩溃

二、基础环境配置

1.代码下载

git clone https://githubfast.com/ultralytics/ultralytics.git
注释ultralytics/pyproject.toml"torch>=1.8.0","torchvision>=0.9.0"
因为我们镜像中本身就自带了torch全家桶,如果不注释会安装torch1.8得最低版本包
之后源码安装该代码

2.环境安装

上述修改完成之后
pip install -e ./ultralytics
torchvision安装【其实就是安装个cpu版本的】
去这里面搜索https://download.pytorch.org/whl/torch_stable.html
torchvision-0.18.0+cpu-cp310-cp310-linux_x86_64.whl
进行本地安装

3.模型下载

yolov8n.pt 
https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt模拟数据下载
https://ultralytics.com/assets/coco8.zip

4.代码修改

ultralytics/ultralytics/data/utils.py
#他下载速度太慢了还容易超时,有需要的自行下载
注释:
check_font("Arial.ttf" if is_ascii(data["names"]) else "Arial.Unicode.ttf")ultralytics/ultralytics/utils/tal.py
修改151-152行
count_tensor = torch.zeros(metrics.shape, dtype=torch.int8, device=topk_idxs.device)
ones = torch.ones_like(topk_idxs[:, :, :1], dtype=torch.int8, device=topk_idxs.device)
将两行的int8改成int32ultralytics/ultralytics/engine/trainer.py
最上面添加两行代码
import torch_mlu
from torch_mlu.utils.model_transfer import transfer

三.单卡推理

from ultralytics import YOLO
import torch_mlu
from torch_mlu.utils.model_transfer import transfer
# Load a model
model = YOLO("yolov8n.yaml")  # build a new model from scratch
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)
# metrics = model.val()  # evaluate model performance on the validation set
results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image
(pytorch) root@notebook-devenviron-0808-143257-13b1tdu-notebook-0:/workspace/volume/guojunceshi2/yolov8/ddd# python dete.py Found https://ultralytics.com/images/bus.jpg locally at bus.jpg
[2024-8-15 23:15:19] [CNNL] [Warning]:[cnnlGetConvolutionForwardAlgorithm] is deprecated and will be removed in the future release. See cnnlFindConvolutionForwardAlgorithm() API for replacement.
[2024-8-15 23:15:19] [CNNL] [Warning]:[cnnlGetNmsWorkspaceSize_v3] is deprecated and will be removed in the future release, please use [cnnlGetNmsWorkspaceSize_v4] instead.
/workspace/volume/guojunceshi2/yolov8/ultralytics/ultralytics/engine/results.py:646: UserWarning: Casting input of dtype int64 to int32, maybe overflow! (Triggered internally at /catch/torch_mlu/csrc/aten/utils/cnnl_util.cpp:117.)n = (boxes.cls == c).sum()  # detections per class
image 1/1 /workspace/volume/guojunceshi2/yolov8/ddd/bus.jpg: 640x480 4 persons, 1 bus, 1 stop sign, 11.7ms
Speed: 3.1ms preprocess, 11.7ms inference, 3.8ms postprocess per image at shape (1, 3, 640, 480)
/opt/py3.10/lib/python3.10/tempfile.py:860: ResourceWarning: Implicitly cleaning up <TemporaryDirectory '/tmp/tmprq9rc0fi'>_warnings.warn(warn_message, ResourceWarning)

是不是就添加两行代码就跑通了,真的很方便

四、单/多卡训练

from ultralytics import YOLO
import torch_mlu
from torch_mlu.utils.model_transfer import transfer
# Load a model
model = YOLO("yolov8n.yaml")  # build a new model from scratch
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)# Use the model
model.train(data="coco8.yaml", epochs=3)  # train the model
metrics = model.val()  # evaluate model performance on the validation set
results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image

在这里插入图片描述
单卡成功训练

from ultralytics import YOLO
import torch_mlu
from torch_mlu.utils.model_transfer import transfer
# Load a model
model = YOLO("yolov8n.yaml")  # build a new model from scratch
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)# Use the model
model.train(data="coco8.yaml", epochs=100,device=[0,1])  # train the model
metrics = model.val()  # evaluate model performance on the validation set
results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image
# path = model.export(format="onnx")  # export the model to ONNX format

在这里插入图片描述
多卡成功训练

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【HBZ分享】Mysql索引的失效场景 以及 创建索引失败报错的原因
  • Spring IOC 小演示
  • 【区块链+乡村振兴】阳光农安农产品质量安全监管与服务平台 | FISCO BCOS应用案例
  • Fal.ai Flux 1-Pro/Viva.ai/哩布哩布AI:AI绘图部分免费工具+原图提示词Prompt
  • 慢SQL优化
  • Vue3+Ts封装类似el-drawer的抽屉组件
  • 【C语言篇】编译和链接以及预处理介绍(下篇)
  • springboot controller参数中如何传递字符串数组
  • MySQL 常用 SQL 语句大全
  • LVS的简单配置及对Mysql主从复制的补充
  • 食品零食小吃商城管理系统-计算机毕设Java|springboot实战项目
  • 求职Leetcode算法题(7)
  • c语言基础知识学习
  • 井字棋游戏(HTML+CSS+JavaScript)
  • Java的反射原理
  • [rust! #004] [译] Rust 的内置 Traits, 使用场景, 方式, 和原因
  • 【面试系列】之二:关于js原型
  • IDEA常用插件整理
  • JS函数式编程 数组部分风格 ES6版
  • SegmentFault 技术周刊 Vol.27 - Git 学习宝典:程序员走江湖必备
  • ⭐ Unity 开发bug —— 打包后shader失效或者bug (我这里用Shader做两张图片的合并发现了问题)
  • Vue学习第二天
  • webpack项目中使用grunt监听文件变动自动打包编译
  • 初探 Vue 生命周期和钩子函数
  • 从重复到重用
  • 记录一下第一次使用npm
  • 使用iElevator.js模拟segmentfault的文章标题导航
  • 事件委托的小应用
  • 微信支付JSAPI,实测!终极方案
  • postgresql行列转换函数
  • 分布式关系型数据库服务 DRDS 支持显示的 Prepare 及逻辑库锁功能等多项能力 ...
  • ​决定德拉瓦州地区版图的关键历史事件
  • # C++之functional库用法整理
  • #Linux(权限管理)
  • $ is not function   和JQUERY 命名 冲突的解说 Jquer问题 (
  • $refs 、$nextTic、动态组件、name的使用
  • %@ page import=%的用法
  • (145)光线追踪距离场柔和阴影
  • (9)STL算法之逆转旋转
  • (day18) leetcode 204.计数质数
  • (八)光盘的挂载与解挂、挂载CentOS镜像、rpm安装软件详细学习笔记
  • (附源码)springboot掌上博客系统 毕业设计063131
  • (回溯) LeetCode 78. 子集
  • (六)软件测试分工
  • ./configure,make,make install的作用(转)
  • .bat批处理(七):PC端从手机内复制文件到本地
  • .MSSQLSERVER 导入导出 命令集--堪称经典,值得借鉴!
  • .net 4.0发布后不能正常显示图片问题
  • .net core 管理用户机密
  • .NET Core中如何集成RabbitMQ
  • .NET Entity FrameWork 总结 ,在项目中用处个人感觉不大。适合初级用用,不涉及到与数据库通信。
  • .NET 编写一个可以异步等待循环中任何一个部分的 Awaiter
  • .Net 高效开发之不可错过的实用工具
  • .pub是什么文件_Rust 模块和文件 - 「译」
  • .vimrc 配置项