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

【深度学习】yolov8n模型的剪枝操作记录

在这里插入图片描述
原始
在这里插入图片描述
剪枝微调后
可以看到模型大小了, 测试结果显示再cpu 上加速5%-10%

from ultralytics import YOLOimport time
# Load a pretrained YOLO11n model
count_num = 500
def test1():model = YOLO("/home/justin/Desktop/code/v8_prun/runs/detect/train3/weights/best.pt")# Define path to directory containing images and videos for inferencesource_img = "/home/data_for_ai_justin3/justin/JersyNumber/num_from_online_from_0822_to_0905/117.jpg"# # Run inference on the source# results = model(source, stream=True,device="cpu")  # generator of Results objectsstart_time = time.time()for i in range(count_num):model.predict(source_img, imgsz=320, conf=0.5,device="cpu")end_time = time.time()print("Time taken for inference:", (end_time - start_time)/count_num)return (end_time - start_time)/count_num
def test2():model = YOLO("/home/justin/Desktop/code/v8_prun/runs/detect/train4/weights/best.pt")# Define path to directory containing images and videos for inferencesource_img = "/home/data_for_ai_justin3/justin/JersyNumber/num_from_online_from_0822_to_0905/117.jpg"# # Run inference on the source# results = model(source, stream=True,device="cpu")  # generator of Results objectsstart_time = time.time()for i in range(count_num):model.predict(source_img, imgsz=320, conf=0.5,device="cpu")end_time = time.time()print("Time taken for inference:", (end_time - start_time)/count_num)return (end_time - start_time)/count_numif __name__ == '__main__':a1 = test1()a2 = test2()print("Speedup:", a1/a2,a1,a2)

测试代码
剪枝的ref:https://blog.csdn.net/Dneccc/article/details/134440603?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-5-134440603-blog-130155924.235v43pc_blog_bottom_relevance_base2&spm=1001.2101.3001.4242.4&utm_relevant_index=8


http://www.mrgr.cn/news/45732.html

相关文章:

  • 职场中的人情世故,你懂了多少?
  • mikrotik ROS container 容器可用的URL
  • windows配置java环境变量
  • D31【python 接口自动化学习】- python基础之输入输出与文件操作
  • VM虚拟机安装 CentOS 7.6 部署宝塔面板实操
  • Arduino UNO R3自学笔记23 之 Arduino如何使用4511控制数码管?
  • 【多重循环在Java中的应用】
  • ES postman操作全量修改,局部修改,删除
  • 今日份总结
  • 机器学习-支撑向量机SVM
  • 【基于YOLOv5的反光衣检测预警系统】可检测图片、视频、摄像头,支持GPU加速检测以及语音播报预警
  • Promise 的描述
  • pg if条件语句
  • Python爬虫之正则表达式于xpath的使用教学及案例
  • 合约测试用例详解
  • [笔记] 仿射变换性质的代数证明
  • EhViewer新手开源项目教程!一文教你安装与高效使用!
  • Verilog开源项目——百兆以太网交换机(八)包缓存模块设计
  • 【专题】数据库系统的基本原理
  • 探索Ultralytics YOLO11在视觉任务上的应用