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

news/2024/10/9 5:24:50 标签: 深度学习, YOLO, 剪枝

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

from ultralytics import YOLO

import 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 inference
    source_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 objects

    start_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 inference
    source_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 objects
    
    start_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

if __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.niftyadmin.cn/n/5695332.html

相关文章

ML 系列:【13 】— Logistic 回归(第 2 部分)

文章目录 一、说明二、挤压方法三、Logistic 回归中的损失函数四、后记 一、说明 ​ 在这篇文章中,我们将深入研究 squashing 方法,这是有符号距离方法(第 12节)的一种很有前途的替代方案。squashing 方法通过提供增强的对异常值…

QT使用websocket实现语音对讲

简介: 本文所描述的功能和代码,是基于QT的开发环境。在QT上使用websocket,接受和发送pcm音频,实现了语音对讲功能。经自测,该功能可以正常使用,以下是相关代码的分享。 void MainWindow::on_pushButton_Ope…

动手学深度学习9.3. 深度循环神经网络-笔记练习(PyTorch)

本节课程地址:58 深层循环神经网络【动手学深度学习v2】_哔哩哔哩_bilibili 本节教材地址:9.3. 深度循环神经网络 — 动手学深度学习 2.0.0 documentation (d2l.ai) 本节开源代码:...>d2l-zh>pytorch>chapter_multilayer-perceptr…

硬件开发笔记(三十一):TPS54331电源设计(四):PCB布板12V转5V电路、12V转3.0V和12V转4V电路

若该文为原创文章,转载请注明原文出处 本文章博客地址:https://hpzwl.blog.csdn.net/article/details/142757509 长沙红胖子Qt(长沙创微智科)博文大全:开发技术集合(包含Qt实用技术、树莓派、三维、OpenCV…

AIGC的底层技术:生成对抗网络(GAN)、变分自编码器(VAE)、预训练模型(如GPT、BERT等)

引言 随着人工智能生成内容(AIGC)技术的快速发展,我们看到它在文本、图像、音频和视频生成等领域的广泛应用。AIGC的核心在于底层技术的支持,本文将深入探讨AIGC的底层技术,包括生成对抗网络(GAN)、变分自编码器(VAE)、预训练模型(如GPT、BERT等),以及相关的深度学…

昆虫分类与检测系统源码分享

昆虫分类与检测系统源码分享 [一条龙教学YOLOV8标注好的数据集一键训练_70全套改进创新点发刊_Web前端展示] 1.研究背景与意义 项目参考AAAI Association for the Advancement of Artificial Intelligence 项目来源AACV Association for the Advancement of Computer Visio…

前端开发中的高级技巧与最佳实践

在前端开发的广阔领域中,不断探索和掌握新的技巧与实践方法是提升开发水平和项目质量的关键。本文将深入探讨一些前端开发中的高级技巧,希望能为广大前端开发者提供有价值的参考和启示。 一、高效的组件化开发 组件化是前端开发中的核心概念之一。通过将页面拆分成独立的、…

设计模式、系统设计 record part04

结构型模式 结构型模式分为: 1.类结构型模式 2.对象结构型模式 3。类结构型,使用继承机制,耦合度高,不灵活 4.对象结构型,使用组合、聚合关系,耦合低,灵活 代理模式 1.代理就是中介 2.静态代理&…