当前位置:网站首页>图形化工具打包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
边栏推荐
猜你喜欢

tensorboard的使用

Babbitt | metauniverse daily must read: is IP authorization the way to break the circle of NFT? What are the difficulties? How should holder choose the cooperation platform

Construction of knowledge map of mall commodities

【安全的办公和生产力应用程序】上海道宁为您提供ONLYOFFICE下载、试用、教程

硬件之OC、OD、推挽解释

When you go to the toilet, you can clearly explain the three Scheduling Strategies of scheduled tasks

Nuggets quantification: obtain data through the history method, and use the same proportional compound weight factor as Sina Finance and snowball. Different from flush

Experience design details

Stored procedures and functions (MySQL)
![[secretly kill little partner pytorch20 days] - [Day1] - [example of structured data modeling process]](/img/f0/79e7915ba3ef32aa21c4a1d5f486bd.jpg)
[secretly kill little partner pytorch20 days] - [Day1] - [example of structured data modeling process]
随机推荐
房费制——登录优化
How to find file accessed / created just feed minutes ago
c语言(字符串)如何把字符串中某个指定的字符删除?
杰理之关于 DAC 输出功率问题【篇】
input_delay
杰理之播内置 flash 提示音控制播放暂停【篇】
Significance and measures of source code confidentiality
C language string sorting
Do you know the five most prominent advantages of E-bidding?
杰理之在非蓝牙模式下,手机连接蓝牙不要跳回蓝牙模式处理方法【篇】
leetcode
【安全的办公和生产力应用程序】上海道宁为您提供ONLYOFFICE下载、试用、教程
尚硅谷JVM-第一章 类加载子系统
A complete tutorial for getting started with redis: AOF persistence
Hazel engine learning (V)
Lavel PHP artisan automatically generates a complete set of model+migrate+controller commands
Utilisation de la promesse dans es6
Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
Jerry's question about DAC output power [chapter]
[socket] ① overview of socket technology