我一直在使用python书架模块来存储下面的python人脸识别模块中的人脸编码。我这样做是为了使实时图像识别过程更快。
然后我再次使用书架模块将这些编码导入另一个脚本中,将它们分配给变量,然后在我的脚本中进一步使用它们。在python空闲环境中以及当我从终端运行它时,这一切都可以正常工作。但是,启动时,机架模块无法导入数据。谁能告诉我为什么在启动时会发生这种情况?我在日志文件中得到的错误如下。我已经坚持了几天。有没有更好的方法来存储和重用编码?预先感谢。
import shelve
shelfFile = shelve.open('face_encodings')
known_encodings = shelfFile['known_encodings']
known_names = shelfFile['known_names']
shelfFile.close()
Traceback (most recent call last): File "/usr/lib/python3.7/shelve.py", line 111, in __getitem__
value = self.cache[key]
KeyError: 'known_encodings'
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last):
File "/home/pi/Desktop/run/testing.py", line 4, in <module>
known_encodings = shelfFile['known_encodings']
File "/usr/lib/python3.7/shelve.py", line 113, in __getitem__
f = BytesIO(self.dict[key.encode(self.keyencoding)])
KeyError: b'known_encodings'