Pyinstaller 打包pytorch 应用

安装pytorch

pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

**注:**打包cudatoolkit会出错(报错如图1所示,如果有解决办法请打在评论区,谢谢!),因此使用pip安装pytorch并手动配置CUDA.
在这里插入图片描述

打包应用

# 安装pyinstaller
pip install pyinstaller
# 使用pyinstaller打包应用(run.py为程序入口文件)
pyinstaller --noconfirm --onefile --console --clean  run.py

遇到的坑

以Yolov5为例

  • Linux下需要将pin_memery = False。
  • 切记一定要关闭360(如果打开360可能会报如下错误)!!!
    如果打开
  • torch_uilt.py: select_device函数中将 “git_describe() or date_modified()” 改为 “date_modified()”。
  • pathlib 尽量使用os.path替代
  • 加入multiprocessing.freeze_support()。
    在这里插入图片描述
  • opencv-python==4.5.3.56 (版本过高打包完运行时会报错)。
  • 打包cudatoolkit会出错(报错如图1所示,如果有解决办法请打在评论区,谢谢!),因此使用pip安装pytorch并手动配置CUDA.
GitHub 加速计划 / yo / yolov5
642
37
下载
yolov5 - Ultralytics YOLOv8的前身,是一个用于目标检测、图像分割和图像分类任务的先进模型。
最近提交(Master分支:3 个月前 )
6981c274 Refactor code for speed and clarity Co-authored-by: UltralyticsAssistant <web@ultralytics.com> 2 个月前
f003c3df This commit resolves an issue where the save-csv command did not write the CSV header. The code now correctly saves the header in the CSV file. Signed-off-by: Ali Ghanbari <alighanbari446@gmail.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> 2 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐