Skip to content

Model won't work after saving and reloading #42

@Primzahlteiler

Description

@Primzahlteiler

hi, I am trying to run the pretrained model after saving it as .pb file. However, when I load the saved model, it no longer works.

when saving the model, I also get a few warnings, one of which says, the input names have changed, because '/' is not allowed.

here is a simple script to test it:

     params = Parameters() # using the standard settings

    # generate some garbage data
     rng = np.random.default_rng()
     pillars = rng.random(size=(4, 12000, 100, 7), dtype=np.float32)
     indices = rng.random(size=(4, 12000, 3), dtype=np.float32)

     pillar_net = build_point_pillar_graph(params)
     pillar_net.load_weights("logs/model.h5")

     x = pillar_net([tf.constant(pillars, name="pillars/input"), tf.constant(indices, name="pillars/indices")])
     # works (garbage out)
     pillar_net.save("saved_model")
     model = tf.saved_model.load("saved_model")
     x = model([tf.constant(pillars, name="pillars/input"), tf.constant(indices, name="pillars/indices")])
     # crash
     x = model([tf.constant(pillars, name="pillars_input"), tf.constant(indices, name="pillars_indices")])
     # doesn't work either
2021-09-16 12:50:02.111392: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.
2021-09-16 12:50:21.236733: W tensorflow/python/util/util.cc:348] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
WARNING:absl:Function `_wrapped_model` contains input name(s) pillars/input, pillars/indices with unsupported characters which will be renamed to pillars_input, pillars_indices in the SavedModel.
Traceback (most recent call last):
  File "/Users/xxx/PycharmProjects/PointPillars/env/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py", line 885, in __call__
    result = self._call(*args, **kwds)
  File "/Users/xxx/PycharmProjects/PointPillars/env/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py", line 933, in _call
    self._initialize(args, kwds, add_initializers_to=initializers)
  File "/Users/xxx/PycharmProjects/PointPillars/env/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py", line 759, in _initialize
    self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
  File "/Users/xxx/PycharmProjects/PointPillars/env/lib/python3.9/site-packages/tensorflow/python/eager/function.py", line 3066, in _get_concrete_function_internal_garbage_collected
    graph_function, _ = self._maybe_define_function(args, kwargs)
  File "/Users/xxx/PycharmProjects/PointPillars/env/lib/python3.9/site-packages/tensorflow/python/eager/function.py", line 3463, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "/Users/xxx/PycharmProjects/PointPillars/env/lib/python3.9/site-packages/tensorflow/python/eager/function.py", line 3298, in _create_graph_function
    func_graph_module.func_graph_from_py_func(
  File "/Users/xxx/PycharmProjects/PointPillars/env/lib/python3.9/site-packages/tensorflow/python/framework/func_graph.py", line 1007, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/Users/xxx/PycharmProjects/PointPillars/env/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py", line 668, in wrapped_fn
    out = weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/Users/xxx/PycharmProjects/PointPillars/env/lib/python3.9/site-packages/tensorflow/python/saved_model/function_deserialization.py", line 288, in restored_function_body
    raise ValueError(
ValueError: Could not find matching function to call loaded from the SavedModel. Got:
  Positional arguments (3 total):
    * [<tf.Tensor 'inputs:0' shape=(4, 12000, 100, 7) dtype=float32>, <tf.Tensor 'inputs_1:0' shape=(4, 12000, 3) dtype=float32>]
    * False
    * None
  Keyword arguments: {}

Expected these arguments to match one of the following 4 option(s):

Option 1:
  Positional arguments (3 total):
    * [TensorSpec(shape=(4, 12000, 100, 7), dtype=tf.float32, name='pillars/input'), TensorSpec(shape=(4, 12000, 3), dtype=tf.int32, name='pillars/indices')]
    * False
    * None
  Keyword arguments: {}

Option 2:
  Positional arguments (3 total):
    * [TensorSpec(shape=(4, 12000, 100, 7), dtype=tf.float32, name='inputs/0'), TensorSpec(shape=(4, 12000, 3), dtype=tf.int32, name='inputs/1')]
    * False
    * None
  Keyword arguments: {}

Option 3:
  Positional arguments (3 total):
    * [TensorSpec(shape=(4, 12000, 100, 7), dtype=tf.float32, name='inputs/0'), TensorSpec(shape=(4, 12000, 3), dtype=tf.int32, name='inputs/1')]
    * True
    * None
  Keyword arguments: {}

Option 4:
  Positional arguments (3 total):
    * [TensorSpec(shape=(4, 12000, 100, 7), dtype=tf.float32, name='pillars/input'), TensorSpec(shape=(4, 12000, 3), dtype=tf.int32, name='pillars/indices')]
    * True
    * None
  Keyword arguments: {}
python-BaseException

btw. I tried multiple ways to infer the model, but just can't seem to get it right. Can someone tell me, what is the proper way to call the loaded model is supposed to be like?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions