gpt4 book ai didi

tensorflow - 运行 object_detection_tutorial 时出现问题 TypeError : load() missing 2 required positional arguments

转载 作者:行者123 更新时间:2023-12-03 00:40:56 25 4
gpt4 key购买 nike

我对 tensorflow 还很陌生,我正在尝试运行object_detection_tutorial。我遇到 TypeError,但不知道如何修复它。

这是 load_model 函数,缺少 2 个参数:

tags:一组字符串标签,用于标识所需的 MetaGraphDef。这些应该与使用 SavedModel save() API 保存变量时使用的标签相对应。

export_dir:SavedModel Protocol Buffer 和要加载的变量所在目录。

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
WARNING:tensorflow:From <ipython-input-9-f8a3c92a04a4>:11: load (from tensorflow.python.saved_model.loader_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-12-e10c73a22cc9> in <module>
1 model_name = 'ssd_mobilenet_v1_coco_2017_11_17'
----> 2 detection_model = load_model(model_name)

<ipython-input-9-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

~/.local/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py in new_func(*args, **kwargs)
322 'in a future version' if date is None else ('after %s' % date),
323 instructions)
--> 324 return func(*args, **kwargs)
325 return tf_decorator.make_decorator(
326 func, new_func, 'deprecated',

TypeError: load() missing 2 required positional arguments: 'tags' and 'export_dir'

你能帮我解决这个问题并运行我的第一个对象检测器吗:D?

最佳答案

我遇到了同样的问题,我正在尝试解决这个问题 1 周。我想解决方案应该是这样的;

model = tf.compat.v2.saved_model.load(str(model_dir), None)

更多详细信息(来自official website);

从export_dir加载SavedModel。

tf.saved_model.load(
export_dir,
tags=None
)

别名:

tf.compat.v1.saved_model.load_v2

tf.compat.v2.saved_model.load

关于tensorflow - 运行 object_detection_tutorial 时出现问题 TypeError : load() missing 2 required positional arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58683841/

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