首页 > 解决方案 > 在 pyinstaller 包中包含 caffee prototxt 文件

问题描述

我正在尝试使用 pyinstaller 为深度学习 python 应用程序创建可执行文件。

该应用程序在虚拟环境中运行并使用 tensorflow 和 opencv,我遇到了一些问题,但我已经解决了,但现在我被卡住了。似乎无法读取程序使用的 deploy.prototxt 文件

错误是:

cv2.error: OpenCV(4.3.0) C:\projects\opencv-python\opencv\modules\dnn\src\caffe\caffe_io.cpp:1121: error: (-2:Unspecified error) FAILED: fs.is_open( )。无法在函数“cv::dnn::ReadProtoFromTextFile”中打开“face_detector\deploy.prototxt”

我将该文件路径包含在规范文件中,但没有成功。我的规格文件是:

    block_cipher = None


a = Analysis(['detect_mask_video.py'],
             pathex=['C:\\Users\\Alexandru\\Envs\\deeplearning_covmask\\Lib\\site-packages', 'E:\\deeplearning\\apps\\face-mask-detector\\face-mask-detector'],
             binaries=[],
             datas=[('C:\\Users\\Alexandru\\Envs\\deeplearning_covmask\\Lib\\site-packages\\astor\\VERSION', 'astor\\VERSION' ),
             ('E:\\deeplearning\\apps\\face-mask-detector\\face-mask-detector\\face_detector\\deploy.prototxt','face_detector\\deploy.prototxt' )],
             hiddenimports=['tensorflow'],
             hookspath=['hooks'],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='detect_mask_video',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )

如何在生成的 exe 中包含 proto 文件?

标签: pythontensorflowopencvpyinstallercaffe

解决方案


文档中并不清楚,但根据我对 pyinstaller 的经验,目标必须是文件夹。在您的规范文件中替换:

('E:\\deeplearning\\apps\\face-mask-detector\\face-mask-detector\\face_detector\\deploy.prototxt','face_detector\\deploy.prototxt' )

('E:\\deeplearning\\apps\\face-mask-detector\\face-mask-detector\\face_detector\\deploy.prototxt','face_detector' )

推荐阅读