gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:39:41 38 4
gpt4 key购买 nike

我正在尝试在 Tensorflow 2 上运行 Tensorflow 对象检测 API 并且出现该错误,有人可以提供解决方案吗?

编码 :

装载机

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

加载标签图

标签将索引映射到类别名称,因此当我们的卷积网络预测为 5 时,我们知道这对应于飞机。这里我们使用内部实用程序函数,但任何返回将整数映射到适当字符串标签的字典的东西都可以
# 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)

为简单起见,我们将在 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

检测

加载对象检测模型:
model_name = 'ssd_mobilenet_v1_coco_11_06_2017'
detection_model = load_model(model_name)

我得到了这个错误
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}

最佳答案

我假设您正在运行 detection_model_zoo tutorial这里。请注意,也许您可​​以从 ssd_mobilenet_v1_coco_11_06_2017 更改模型名称。至 ssd_mobilenet_v1_coco_2017_11_17 ,这将解决我测试中的问题。

这些文件的内容可以在下面看到:

# 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

引用:
  • Where to find tensorflow pretrained models (list or download link)
  • detect_model_zoo
  • Using the SavedModel format official blog
  • 关于tensorflow - SavedModel 文件不存在于saved_model/{saved_model.pbtxt|saved_model.pb},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59342048/

    38 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com