运行object_detection_tutorial TypeError的问题:load()缺少2个必需的位置参数

Dom*_*nik 5 tensorflow

我对tensorflow非常陌生,并且正在尝试运行object_detection_tutorial。我收到TypeErrror,不知道如何解决。

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

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

export_dir:SavedModel协议缓冲区和要加载的变量所在的目录。

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
Run Code Online (Sandbox Code Playgroud)
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'
Run Code Online (Sandbox Code Playgroud)

您能帮我解决这个问题并运行我的第一个物体检测器:D吗?

Onu*_*kin 26

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

model = tf.compat.v2.saved_model.load(str(model_dir), None)
Run Code Online (Sandbox Code Playgroud)

更多细节将是(来自官方网站);

从 export_dir 加载 SavedModel。

tf.saved_model.load(
    export_dir,
    tags=None
)
Run Code Online (Sandbox Code Playgroud)

别名:

tf.compat.v1.saved_model.load_v2

tf.compat.v2.saved_model.load
Run Code Online (Sandbox Code Playgroud)

  • @OnurBaskin稍后会出现错误: TypeError: int() argument must be a string, a bytes-like object or a number, not 'Tensor' (4认同)
  • 我使用了你的解决方案并遇到了另一个错误。我更新了我能更新的一切并且它有效!我还遇到了 pathlib 未安装的错误。 (2认同)
  • @OnurBaskin 我很困惑。我认为对象检测 API 仅与 TensorFlow 1 版本兼容。 (2认同)