当前位置:网站首页>图形化工具打包YOLOv5,生成可执行文件EXE
图形化工具打包YOLOv5,生成可执行文件EXE
2022-07-06 20:07:00 【马少爷】
环境
windows 10 64bit
auto-py-to-exe 2.10.1
前言
Python 项目打包是很多新手经常会问的问题,之前也有文章介绍过如何使用 pyinstaller 来打包生成可执行文件,只不过打包过程是基于命令行的。本文介绍的这个工具,auto-py-to-exe,它是 pyinstaller 的 GUI 版本,对新手更加友好,点点鼠标就可以轻松搞定,那么,快开始吧。
安装
使用 pip 直接安装
pip install auto-py-to-exe
或者拉取源码,解压后进入根目录,执行
python setup.py install
打包示例
本文使用之前的 yolov5-pyqt5 项目进行打包,这里需要注意一点,如果你是使用的 python 虚拟环境,那必须在这个虚拟环境中去安装 auto-py-to-exe
项目代码拉下来之后,修改 main.py,将
self.device = select_device(self.opt.device)
改为
# gpu
self.device = torch.device('cuda:0')
# 如果只有cpu的话,就改成
# self.device = torch.device('cpu')
为什么要这么改?这里主要是 select_device 方法中使用到了 subprocess,而 pyinstaller 在打包 subprocess 方法时会报错,如果去修改 subprocess 部分的代码就有点麻烦了,为简单起见,就不去调用这个方法了,具体的可以参考 https://xugaoxiang.com/2019/12/04/pyqt5-4-pyinstaller/
然后,打开 auto-py-to-exe, 脚本文件选择 yolov5-pyqt5 文件夹下的 main.py,选择单文件,也就是最后就只生成一个可执行文件
在高级选项卡里,点击 --hidden-import 右侧的加号,然后填上 modles.yolo,否则,生成的 exe 运行时会报如下的错误
Traceback (most recent call last):
File "detect_image.py", line 405, in <module>
File "detect_image.py", line 365, in main
File "detect_image.py", line 293, in detection_alertarea
File "detect_image.py", line 79, in __init__
File "models\experimental.py", line 137, in attempt_load
File "torch\serialization.py", line 594, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "torch\serialization.py", line 853, in _load
result = unpickler.load()
ModuleNotFoundError: No module named 'models.yolo'
[12976] Failed to execute script detect_image

其它类似 No module named xxx 的错误,也是同样的解决方法
在我们做配置勾选的过程中,当前命令会显示对应的 pyinstaller 指令,如果你没有安装 auto-py-to-exe,只安装了 pyinstaller,那复制这行命令,同样也是可以打包成功的
如果没有报错,项目生成的 exe 文件会默认放在 C:\Users\用户名\output 下
准备好官方的模型文件 yolov5s.pt,放在 weights 文件夹下,然后双击 exe 文件

最后,选择一张测试图片进行测试,功能正常

参考资料
https://github.com/brentvollebregt/auto-py-to-exe
https://xugaoxiang.com/2019/12/04/pyqt5-4-pyinstaller/
https://github.com/xugaoxiang/yolov5-pyqt5
边栏推荐
- 【Swift】学习笔记(一)——熟知 基础数据类型,编码风格,元组,主张
- [socket] ① overview of socket technology
- Utilisation de la promesse dans es6
- 杰理之发射端在接收端关机之后假死机【篇】
- c语言字符串排序
- Numpy中排序操作partition,argpartition,sort,argsort
- Oracle connection pool is not used for a long time, and the connection fails
- When you go to the toilet, you can clearly explain the three Scheduling Strategies of scheduled tasks
- 【安全的办公和生产力应用程序】上海道宁为您提供ONLYOFFICE下载、试用、教程
- How-PIL-to-Tensor
猜你喜欢

Leetcode 77: combination

Use of tensorboard

密码学系列之:在线证书状态协议OCSP详解
![[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication](/img/09/b9d50f7a10e6898ac4088ee005d00b.png)
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication

掘金量化:通过history方法获取数据,和新浪财经,雪球同用等比复权因子。不同于同花顺

2022 spring recruitment begins, and a collection of 10000 word interview questions will help you

Decoration design enterprise website management system source code (including mobile source code)

Flink task exit process and failover mechanism
![Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]](/img/f4/8464bf9b66a1215265ac873f286688.png)
Jericho turns on the display icon of the classic Bluetooth hid mobile phone to set the keyboard [chapter]

Centerx: open centernet in the way of socialism with Chinese characteristics
随机推荐
Leetcode-02 (linked list question)
凌云出海记 | 易点天下&华为云:推动中国电商企业品牌全球化
Oracle connection pool is not used for a long time, and the connection fails
【安全的办公和生产力应用程序】上海道宁为您提供ONLYOFFICE下载、试用、教程
centerX: 用中国特色社会主义的方式打开centernet
CVPR 2022 最佳论文候选 | PIP: 6个惯性传感器实现全身动捕和受力估计
Lavel PHP artisan automatically generates a complete set of model+migrate+controller commands
uniapp适配问题
[cpk-ra6m4 development board environment construction based on RT thread studio]
Cocos2d-x Box2D物理引擎编译设置
leetcode
杰理之电话本获取【篇】
2022.6.28
SQL Tuning Advisor一个错误ORA-00600: internal error code, arguments: [kesqsMakeBindValue:obj]
上个厕所的功夫,就把定时任务的三种调度策略说得明明白白
杰理之FM 模式单声道或立体声选择设置【篇】
Intelligent static presence detection scheme, 5.8G radar sensing technology, human presence inductive radar application
HDU ACM 4578 Transformation-&gt;段树-间隔的变化
树莓派设置静态ip
leetcode