Skip to content

Document behavior of save versus save_weights #899

@mhucka

Description

@mhucka

In issue #56, there is a request for improving the docs:

Would like to +1 this, and ask that it is made clear(er) in the documentation that although save won't work, save_weights will.

This is because the error given when calling save doesn't indicate that this is the problem; in my case, I got


File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 98, in encode_structure

    return self._map_structure(nested_structure, self._get_encoders())

  File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 82, in _map_structure

    return do(pyobj, recursion_fn)

  File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 237, in do_encode

    pair.value.CopyFrom(encode_fn(named_tuple_value._asdict()[key]))

  File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 82, in _map_structure

    return do(pyobj, recursion_fn)

  File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 206, in do_encode

    encoded_dict.dict_value.fields[key].CopyFrom(encode_fn(value))

  File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/saved_model/nested_structure_coder.py", line 83, in _map_structure

    raise NotEncodableError(

tensorflow.python.saved_model.nested_structure_coder.NotEncodableError: No encoder for object [<tensorflow.python.keras.initializers.initializers_v2.RandomUniform object at 0x7f241a041880>] of type [<class 'tensorflow.python.keras.initializers.initializers_v2.RandomUniform'>].

Only when explicitly calling the model's get_config() method did I get


File "learn_params.py", line 194, in <module>

    print(model.get_config())

  File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/keras/engine/functional.py", line 598, in get_config

    return copy.deepcopy(get_network_config(self))

  File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/keras/engine/functional.py", line 1278, in get_network_config

    layer_config = serialize_layer_fn(layer)

  File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 250, in serialize_keras_object

    raise e

  File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 245, in serialize_keras_object

    config = instance.get_config()

  File "(virtual environment)/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py", line 676, in get_config

    raise NotImplementedError('Layer %s has arguments in `__init__` and '

NotImplementedError: Layer ControlledPQC has arguments in `__init__` and therefore must override `get_config`.

Originally posted by @mikeevmm in #56

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/docsInvolves documentation – problems, ideas, requestskind/feature-requestNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions