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

问题描述 投票:0回答:1

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

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

tags:一组字符串标签,用于标识所需的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
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吗?

tensorflow
1个回答
0
投票
的集合]

我有同样的问题,我现在想解决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
© www.soinside.com 2019 - 2024. All rights reserved.