Models: '_UserObject' object has no attribute 'summary'

Created on 29 Jul 2020  Â·  15Comments  Â·  Source: tensorflow/models

Hello, I'm trying to load a ssd_resnet50_v1_fpn_640x640_coco17_tpu-8 I just fine tuned but I'm coming across this error:

'_UserObject' object has no attribute 'summary'

Here are the 4 lines of code I have;

import tensorflow as tf

model_dir = 'C:/Users/Windows/Documents/Tensorflow_Obj_Det_API/models/research/object_detection/inference_graph/saved_model'

trained_model = tf.saved_model.load(model_dir)

trained_model.summary()

I've tried including the save_model.pb on the path to the model but then I get this error:

SavedModel file does not exist at: C:\Users\Windows\Documents\Tensorflow_Obj_Det_API\models\research\object_detection\inference_graph\saved_model\saved_model.pb/{saved_model.pbtxt|saved_model.pb}

Anyone knows how to load a trained model to do inference?

research support

Most helpful comment

I ran in to the same issue. Using the saved_model.pb from the object detection api. Tried tf.saved_model.load as well as tf.keras.models.load_model. Both gave this error:

AttributeError: '_UserObject' object has no attribute 'summary'

All 15 comments

I'm using the tf.keras.models.load_model function instead of tf.saved_model.load to load the model.

Now I'm getting a different error;

spec = fn.concrete_functions[0].structured_input_signature[0][0]
IndexError: list index out of range

Did you already solved your problems? I ran in to the same issue. Using the saved_model.pb from the object detection api. Tried tf.saved_model.load as well as tf.keras.models.load_model

@nicholasguimaraes Can you please share a standalone code to reproduce the issue? Thanks!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

I ran in to the same issue. Using the saved_model.pb from the object detection api. Tried tf.saved_model.load as well as tf.keras.models.load_model. Both gave this error:

AttributeError: '_UserObject' object has no attribute 'summary'

I am also getting the same error with models:

  • SSD with Resnet 50 v1 FPN feature extractor, shared box predictor and focal loss (a.k.a Retinanet).
  • SSD with EfficientNet-b4 + BiFPN feature extractor, shared box predictor and focal loss (a.k.a EfficientDet-d4)

The config files are the same the ones in: models/research/object_detection/configs/tf2/

I first train with: models/research/object_detection/model_main_tf2.py

And then I export with: models/research/object_detection/exporter_main_v2.py

But then when I try to load the exported model I get the error:

Traceback (most recent call last):
  File "/Users/harrythomas/projects/xrfiber_effdet/pb_to_coreml.py", line 82, in <module>
    main()
  File "/Users/harrythomas/projects/xrfiber_effdet/pb_to_coreml.py", line 22, in main
    model = tf.keras.models.load_model(PATH_TO_MODEL, compile=False)
  File "/Users/harrythomas/opt/anaconda3/envs/effdetvenv/lib/python3.8/site-packages/tensorflow/python/keras/saving/save.py", line 187, in load_model
    return saved_model_load.load(filepath, compile, options)
  File "/Users/harrythomas/opt/anaconda3/envs/effdetvenv/lib/python3.8/site-packages/tensorflow/python/keras/saving/saved_model/load.py", line 120, in load
    model = tf_load.load_internal(
  File "/Users/harrythomas/opt/anaconda3/envs/effdetvenv/lib/python3.8/site-packages/tensorflow/python/saved_model/load.py", line 632, in load_internal
    loader = loader_cls(object_graph_proto, saved_model_proto, export_dir,
  File "/Users/harrythomas/opt/anaconda3/envs/effdetvenv/lib/python3.8/site-packages/tensorflow/python/keras/saving/saved_model/load.py", line 194, in __init__
    super(KerasObjectLoader, self).__init__(*args, **kwargs)
  File "/Users/harrythomas/opt/anaconda3/envs/effdetvenv/lib/python3.8/site-packages/tensorflow/python/saved_model/load.py", line 130, in __init__
    self._load_all()
  File "/Users/harrythomas/opt/anaconda3/envs/effdetvenv/lib/python3.8/site-packages/tensorflow/python/keras/saving/saved_model/load.py", line 221, in _load_all
    self._finalize_objects()
  File "/Users/harrythomas/opt/anaconda3/envs/effdetvenv/lib/python3.8/site-packages/tensorflow/python/keras/saving/saved_model/load.py", line 526, in _finalize_objects
    _finalize_saved_model_layers(layers_revived_from_saved_model)
  File "/Users/harrythomas/opt/anaconda3/envs/effdetvenv/lib/python3.8/site-packages/tensorflow/python/keras/saving/saved_model/load.py", line 706, in _finalize_saved_model_layers
    inputs = infer_inputs_from_restored_call_function(call_fn)
  File "/Users/harrythomas/opt/anaconda3/envs/effdetvenv/lib/python3.8/site-packages/tensorflow/python/keras/saving/saved_model/load.py", line 982, in infer_inputs_from_restored_call_function
    spec = fn.concrete_functions[0].structured_input_signature[0][0]
IndexError: list index out of range

System Information:

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 18.04
  • Mobile device name if the issue happens on a mobile device:
  • TensorFlow installed from (source or binary): pip
  • TensorFlow version (use command below): 2.3.1
  • Python version: 3.8.3
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version: CUDA 10.1.243, cuDNN 7.6.4
  • GPU model and memory: 2x 1080 Ti 10Gb

Code:

Import tensorflow as tf
import object_detection.models.keras_models.resnet_v1
import object_detection.models.feature_map_generators
PATH_TO_MODEL = ‘./saved_model/‘
model = tf.keras.models.load_model(PATH_TO_MODEL)

I can load and make predictions with

model = tf.saved_model.load(PATH_TO_MODEL)
tf_out = model(inputs)

However I wish to load the saved model so that I can edit it and then export it with coreML.

has this issue been resolved yet? I'm getting the same issue.

I am also getting the same issue. I was tring to load model from object detection model zone: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md

Same here issue when using object detection model in google colab

Is there any progress on this ?

I'm trying to restore models in from both the Tensorflow hub as well as the object detection model zoo.

However in both cases I only get "._UserObject at 0x7f7431ec2070>" something like this. This has none of the usual model functionalities.

For Example the code I am using is the following:

test = tf.saved_model.load('models/faster_rcnn_resnet152_v1_800x1333_coco17_gpu-8/saved_model/')

The model has been download from here: http://download.tensorflow.org/models/object_detection/tf2/20200711/faster_rcnn_resnet152_v1_800x1333_coco17_gpu-8.tar.gz

I also used other loading methods such as: test_2 = tf.keras.models.load_model('models/faster_rcnn_resnet152_v1_800x1333_coco17_gpu-8/saved_model/')

But in both cases I don't get a fully functional model.

What I was expecting to get was a model with the usual compile(), fit() and predict() functions. However I am not sure if this is actually possible with the model zoo and tensorflow hub models.

I don't have any experiences with those pretrained models and therefore any help and suggestions are welcome.

``

Does someone have any solution to this?

I think the problem here is that the saved model wasn't created using Keras. so of course, when you load it you don't get a Keras object. It should be possible to create a new model with the same architecture as the one you want to load using Keras and load the weights from there. something like this:

keras_model.set_weights(loaded_model.get_weights())

I convert model from pytorch to tensorflow through onnx and I've got same issue right now...

Is this issue still being worked on?

I've got the same issue with a model I've converted from onnx... Is this issue going to be resolved ever?

Was this page helpful?
0 / 5 - 0 ratings