运行 object_detection_tutorial TypeError 的问题:load() 缺少 2 个必需的位置参数 [英] Problem with running object_detection_tutorial TypeError: load() missing 2 required positional arguments

查看:16
本文介绍了运行 object_detection_tutorial TypeError 的问题:load() 缺少 2 个必需的位置参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 tensorflow 还很陌生,我正在尝试运行 object_detection_tutorial.我遇到了 TypeErrror,但不知道如何解决.

I'm pretty new to tensorflow and I'm trying to run object_detection_tutorial. I'm getting TypeErrror and don't know how to fix it.

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

This is load_model function which misses 2 arguments:

tags:用于标识所需 MetaGraphDef 的字符串标签集.这些应该对应于使用 SavedModel save() API 保存变量时使用的标签.

tags: Set of string tags to identify the required MetaGraphDef. These should correspond to the tags used when saving the variables using the SavedModel save() API.

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

export_dir: Directory in which the SavedModel protocol buffer and variables to be loaded are located.

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 吗?

Can you help me fix this and run my first object detector :D?

推荐答案

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

I had the same problem and i'm trying to solve this for 1 week now. I guess the solution should be this;

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

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

More detail would be (from the official website) ;

从 export_dir 加载 SavedModel.

Load a SavedModel from export_dir.

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

别名:

tf.compat.v1.saved_model.load_v2

tf.compat.v2.saved_model.load

这篇关于运行 object_detection_tutorial TypeError 的问题:load() 缺少 2 个必需的位置参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆