简体   繁体   English

SavedModel 文件不存在于 saved_model/{saved_model.pbtxt|saved_model.pb}

[英]SavedModel file does not exist at saved_model/{saved_model.pbtxt|saved_model.pb}

I'm try running Tensorflow Object Detection API on Tensorflow 2 and I got that error, can someone have a solution?我正在尝试运行 Tensorflow Object Detection API on Tensorflow 2 我得到了那个错误,有人可以解决吗?

The code:代码:

Loader装载机

def load_model(model_name):
  base_url = 'http://download.tensorflow.org/models/object_detection/'
  model_file = model_name + '.tar.gz'
  model_dir = tf.keras.utils.get_file(
    fname=model_name, 
    origin=base_url + model_file,
    untar=True)
​
  model_dir = pathlib.Path(model_dir)/"saved_model"
​
  model = tf.saved_model.load(str(model_dir))
  model = model.signatures['serving_default']
​
  return model

Loading label map加载中 label map

Label maps map indices to category names, so that when our convolution.network predicts 5, we know that this corresponds to airplane. Label 将 map 索引映射到类别名称,因此当我们的卷积网络预测 5 时,我们知道这对应于飞机。 Here we use internal utility functions, but anything that returns a dictionary mapping integers to appropriate string labels would be fine这里我们使用内部效用函数,但任何返回字典映射整数到适当字符串标签的东西都可以

# List of the strings that is used to add correct label for each box.
PATH_TO_LABELS = 'data/mscoco_label_map.pbtxt'
category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)

For the sake of simplicity we will test on 2 images:为了简单起见,我们将在 2 张图像上进行测试:

# If you want to test the code with your images, just add path to the images to the TEST_IMAGE_PATHS.
PATH_TO_TEST_IMAGES_DIR = pathlib.Path('test_images')
TEST_IMAGE_PATHS = sorted(list(PATH_TO_TEST_IMAGES_DIR.glob("*.jpg")))
TEST_IMAGE_PATHS

Detection检测

Load an object detection model:加载一个object检测model:

model_name = 'ssd_mobilenet_v1_coco_11_06_2017'
detection_model = load_model(model_name)

and i got this error我得到了这个错误

OSError                                   Traceback (most recent call last)
<ipython-input-7-e89d9e690495> in <module>
      1 model_name = 'ssd_mobilenet_v1_coco_11_06_2017'
----> 2 detection_model = load_model(model_name)

<ipython-input-4-f8a3c92a04a4> in load_model(model_name)
      9   model_dir = pathlib.Path(model_dir)/"saved_model"
     10 
---> 11   model = tf.saved_model.load(str(model_dir))
     12   model = model.signatures['serving_default']
     13 

D:\Anaconda\lib\site-packages\tensorflow_core\python\saved_model\load.py in load(export_dir, tags)
    515     ValueError: If `tags` don't match a MetaGraph in the SavedModel.
    516   """
--> 517   return load_internal(export_dir, tags)
    518 
    519 

D:\Anaconda\lib\site-packages\tensorflow_core\python\saved_model\load.py in load_internal(export_dir, tags, loader_cls)
    524     # sequences for nest.flatten, so we put those through as-is.
    525     tags = nest.flatten(tags)
--> 526   saved_model_proto = loader_impl.parse_saved_model(export_dir)
    527   if (len(saved_model_proto.meta_graphs) == 1
    528       and saved_model_proto.meta_graphs[0].HasField("object_graph_def")):

D:\Anaconda\lib\site-packages\tensorflow_core\python\saved_model\loader_impl.py in parse_saved_model(export_dir)
     81                   (export_dir,
     82                    constants.SAVED_MODEL_FILENAME_PBTXT,
---> 83                    constants.SAVED_MODEL_FILENAME_PB))
     84 
     85 

OSError: SavedModel file does not exist at: C:\Users\Asus\.keras\datasets\ssd_mobilenet_v1_coco_11_06_2017\saved_model/{saved_model.pbtxt|saved_model.pb}

I assume that you are running detection_model_zoo tutorial here.我假设您在这里运行detection_model_zoo 教程 Note that maybe you can change the model name from ssd_mobilenet_v1_coco_11_06_2017 to ssd_mobilenet_v1_coco_2017_11_17 , this will solve the problem in my test.请注意,也许您可​​以将模型名称从ssd_mobilenet_v1_coco_11_06_2017ssd_mobilenet_v1_coco_2017_11_17 ,这将解决我测试中的问题。

The content of these files can be seen below:这些文件的内容可以在下面看到:

# ssd_mobilenet_v1_coco_11_06_2017
frozen_inference_graph.pb  model.ckpt.data-00000-of-00001  model.ckpt.meta
graph.pbtxt        model.ckpt.index

# ssd_mobilenet_v1_coco_2017_11_17
checkpoint         model.ckpt.data-00000-of-00001  model.ckpt.meta
frozen_inference_graph.pb  model.ckpt.index        saved_model

Reference:参考:

  1. Where to find tensorflow pretrained models (list or download link) 在哪里可以找到 tensorflow 预训练模型(列表或下载链接)
  2. detect_model_zoo detect_model_zoo

  3. Using the SavedModel format official blog使用 SavedModel 格式官方博客

In my case, this code is worked for me.就我而言,此代码对我有用。 I gave the path of the folder of my .pd file that was created by model checkpoint module :我给出了由模型检查点模块创建的 .pd 文件的文件夹路径:

import tensorflow as tf
if __name__ == '__main__':
    # Update the input name and path for your Keras model
    input_keras_model = 'my path/weights/my_trained_model/{the files inside this folder are: assets(folder), variables(folder),keras_metadata.pd,saved_model.pd}'


    model = tf.keras.models.load_model(input_keras_model)

Do not link all the way to the model name.不要一直链接到模型名称。 Use the pathname to the folder containing the model.使用包含模型的文件夹的路径名。

I was getting exactly this error when trying to use the saved_model.pb file.我在尝试使用 saved_model.pb 文件时遇到了这个错误。 I had gotten the.pb file along with a pre-trained model following some tutorial.我已经按照一些教程获得了 .pb 文件以及预训练的 model。

It was happening due to the following reasons:它的发生是由于以下原因:

  • first your already existing saved_model.pb file might be corrupt首先,您已经存在的 saved_model.pb 文件可能已损坏
  • second as the user @Mark Silla has mentioned, you are giving the wrong path to the file, just give the path of folder containing the.pb file excluding the file name其次,正如用户@Mark Silla 所提到的,您提供了错误的文件路径,只需提供包含 .pb 文件的文件夹路径,不包括文件名
  • third, it might be due to Tensorflow versioning issues第三,可能是由于 Tensorflow 版本问题

I had to follow all of the above steps and upgraded Tensorflow from v2.3 to v2.3, and it finally created a new saved_model.pb which was not corrupt and I could run it.我必须按照上述所有步骤将 Tensorflow 从 v2.3 升级到 v2.3,它最终创建了一个新的 saved_model.pb,它没有损坏,我可以运行它。

暂无
暂无

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

相关问题 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} 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 文件不存在于: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 文件不存在于: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 文件不存在于: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} 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} 腌制文件存在但其中没有任何内容 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 如何正确创建saved_model.pb? - How to correctly create saved_model.pb?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM