python - 在 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 文件?
解决方案
文档中并不清楚,但根据我对 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' )
推荐阅读
- android - React-Native 项目未在 Expo go 应用程序中打开
- aws-sdk-js - RedshiftDataClient BatchExecuteStatement 将所有查询合二为一
- python - 如何在 Python 中从此文本文件中获取接口名称和 IP 地址
- dataframe - 迭代元组列表以创建新列
- html - 嵌入的 Youtube 视频未填满屏幕
- java - 如何简化太多if条件并捕获java中的错误输出字段
- python - 我将如何使用 python split() 方法,但它以多个字符拆分的方式,而不仅仅是输入的特定字符串?
- java - testImplementation 的 Gradle 配置不起作用
- java - 2秒后点击一个按钮
- python - 用于基于结构的数组的 Python