[英]OSError: SavedModel file does not exist at: model\mymodel.h5/{saved_model.pbtxt|saved_model.pb}
I use tensorflow 2.2 with python 3.7 and windows 10. I import a training model with tensorlfow 1.x.我使用tensorflow 2.2与Z23EEEB4347BDD26BFC6BFC6B7555DDDDDDDD DDZ 3.7和Z0F4137ED1502B5045D6083A.25555C4255C4F5F.5F.5.FARF.BB542F.ICTINCE When I import with the terminal everything is fine.当我使用终端导入时,一切都很好。 But when I freeze my code, the file is no longer found.但是当我冻结我的代码时,不再找到该文件。
Here are my files:这是我的文件:
main.py
\ codes
import.py
\ model
__init__.py
mymodel.h5
My import.py:我的 import.py:
from .model import mymodel
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
model = load_model(mymodel)
My init .py code:我的初始化.py 代码:
from os import path
import sys
if getattr(sys, 'frozen', False):
MODEL_DIRECTORY = path.join(path.dirname(sys.executable), 'model')
else:
MODEL_DIRECTORY = path.dirname(__file__)
mymodel= path.join(MODEL_DIRECTORY, 'mymodel.h5')
The error I got:我得到的错误:
SavedModel file does not exist at: exe.win-amd64-3.7\model\mymode SavedModel 文件不存在于:exe.win-amd64-3.7\model\mymode
It's clear you're getting part of the python binary mixed from the message.很明显,您从消息中得到了 python 二进制文件的一部分。 sys.executable
is a link to this binary... Probably not what you thought. sys.executable
是指向此二进制文件的链接...可能不是您想的那样。
if getattr(sys, 'frozen', False):
MODEL_DIRECTORY = path.join(path.dirname(sys.executable), 'model')
else:
MODEL_DIRECTORY = path.dirname(__file__)
I'm pretty sure you want:我很确定你想要:
MODEL_DIRECTORY = path.join(path.dirname(__file__), 'codes', 'model', 'mymodel.h5');
Also your directory structure is weird...你的目录结构也很奇怪......
|-|main.py
|-|__init__.py
|-|data
| | |-|model
| | | |-|mymodel.h5
|-|code
| |-|__init__.py
| |-|import.py #wtf is an import.py and why is it down here.
__file__
references the current file so if you have this structure and do this from main.py: __file__
引用当前文件,因此如果您有此结构并从 main.py 执行此操作:
model_dir = Path(path.dirname(__file__), "data", "model", "mymodel.h5")
this is using Pathlib.Path
and os.path.dirname
. model_dir = Path(path.dirname(__file__), "data", "model", "mymodel.h5")
这是使用Pathlib.Path
和os.path.dirname
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.