这个load()缺少了2个必要的位置参数,'tags'和'export_dir'。'tags'和'export_dir'.这是我从Github运行对象检测API时得到的错误。

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

我下载了这个API,并按照他们的建议使用了TensorFlow 1.15,但无论我做什么,我都一直得到这个错误信息

以下是给我错误的代码

model_name = 'ssd_mobilenet_v1_coco_2017_11_17'
detection_model = load_model(model_name)

问题的原因似乎是函数 load_model

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

所以我试着用这个页面的解决方案添加参数。运行object_detection_tutorial时出现问题 TypeError: load()缺少2个所需的位置参数。

当我应用了修复后(以我稀疏的知识),这是代码。

    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.compat.v1.saved_model.load(str(model_dir),None)**#change i made**
      model = model.signatures['serving_default']

      return model

新的错误不断出现,如。

<ipython-input-23-e10c73a22cc9> in <module>
      1 model_name = 'ssd_mobilenet_v1_coco_2017_11_17'
----> 2 detection_model = load_model(model_name)
<ipython-input-20-11f71129951a> in load_model(model_name)
      9   model_dir = pathlib.Path(model_dir)/"saved_model"
     10 
---> 11   model = tf.compat.v1.saved_model.load(str(model_dir),None)
     12   model = model.signatures['serving_default']
     13 
D:\Anaconda\envs\work\lib\site-packages\tensorflow_core\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 1 required positional argument: 'export_dir'

Any help is appreciated ,Thank You very much.

tensorflow object-detection-api
1个回答
0
投票

试试这个:-代码在tensorflow = 2.2.0中工作正常,没有任何变化。

© www.soinside.com 2019 - 2024. All rights reserved.