欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 游戏 > 【深度学习】yolov8n模型的剪枝操作记录

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

2025/10/29 3:33:29 来源:https://blog.csdn.net/weixin_40293999/article/details/142771105  浏览:    关键词:【深度学习】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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词