简体   繁体   English

OSError:SavedModel 文件不存在于:model\mymodel.h5/{saved_model.pbtxt|saved_model.pb}

[英]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.Pathos.path.dirname

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSError:SavedModel 文件不存在于:cnnCat2.h5\{saved_model.pbtxt|saved_model.pb} - OSError: SavedModel file does not exist at: cnnCat2.h5\{saved_model.pbtxt|saved_model.pb} OSError:SavedModel 文件不存在于:/content\model\2016/{saved_model.pbtxt|saved_model.pb} - OSError: SavedModel file does not exist at: /content\model\2016/{saved_model.pbtxt|saved_model.pb} OSError:SavedModel 文件不存在于:model/CPN_Model.h5\{saved_model.pbtxt|saved_model.pb} - OSError: SavedModel file does not exist at: model/CPN_Model.h5\{saved_model.pbtxt|saved_model.pb} OSError:SavedModel 文件不存在于:../dnn/mpg_model.h5/{saved_model.pbtxt|saved_model.pb} - OSError: SavedModel file does not exist at: ../dnn/mpg_model.h5/{saved_model.pbtxt|saved_model.pb} SavedModel 文件不存在于:model.h5/{saved_model.pbtxt|saved_model.pb} - SavedModel file does not exist at: model.h5/{saved_model.pbtxt|saved_model.pb} 腌制文件存在但其中没有任何内容 OSError:SavedModel 文件不存在于:{saved_model.pbtxt|saved_model.pb} - a pickled file exists but nothing in it OSError: SavedModel file does not exist at: {saved_model.pbtxt|saved_model.pb} OSError:SavedModel 文件不存在于:C:\Users\Munib\New folder/{saved_model.pbtxt|saved_model.pb} - OSError: SavedModel file does not exist at: C:\Users\Munib\New folder/{saved_model.pbtxt|saved_model.pb} OSError:SavedModel 文件不存在于:C:/User/A/model/saved_model.pb - OSError: SavedModel file does not exist at: C:/User/A/model/saved_model.pb FAILED_PRECONDITION:错误:SavedModel目录gs:// mybucket1 /应该完全包含[saved_model.pb,saved_model.pbtxt]中的一个 - FAILED_PRECONDITION: Error: SavedModel directory gs://mybucket1/ is expected contain exactly one of [saved_model.pb, saved_model.pbtxt] 如何正确创建saved_model.pb? - How to correctly create saved_model.pb?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM