Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with running object_detection_tutorial TypeError: load() missing 2 required positional arguments

Tags:

tensorflow

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.

This is load_model function which misses 2 arguments:

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: 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'

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

like image 787
Dominik Avatar asked Nov 03 '19 19:11

Dominik


People also ask

How to fix Python TypeError missing 2 required positional arguments?

The Python "TypeError: missing 2 required positional arguments" occurs when we forget to provide 2 required arguments when calling a function or method. To solve the error, specify the arguments when calling the function or set default values for the arguments. Here is an example of how the error occurs.

How to solve the error when a function takes 2 arguments?

One way to solve the error is to provide a value for the arguments. We passed values for the arguments to the function which solves the error. If we define a function that takes 2 arguments, we have to provide values for the arguments when the function is called. An alternative solution is to set default values for the arguments.

Does TensorFlow object detection API support TensorFlow 2 (TF2)?

Update: The TensorFlow Object Detection API supports both TensorFlow 2 (TF2) and TensorFlow 1 (TF1) Show activity on this post. If you would just like to make a perdiction then you can also use load the model as below:


1 Answers

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) ;

Load a SavedModel from export_dir.

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

Aliases:

tf.compat.v1.saved_model.load_v2

tf.compat.v2.saved_model.load
like image 194
Onur Baskin Avatar answered Oct 19 '22 04:10

Onur Baskin