Skip to content

Any recommended way to save a tf privacy model? #559

@zedoul

Description

@zedoul

Hi, thanks for the open source, a great work.

If one "naively" saves a tf privacy model, it will face an issue.

Let say, you save the model by TF recommended methods, such as
tf.saved_model.save(model, "model.tfmodel")
or
model.save("model.tfmodel", save_format = 'tf')

It will resulted in an error:

`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[19], line 9
----> 9 loaded_model = tf.keras.models.load_model("model.tfmodel")

File /usr/local/lib/python3.11/dist-packages/keras/src/saving/saving_api.py:262, in load_model(filepath, custom_objects, compile, safe_mode, **kwargs)
254 return saving_lib.load_model(
255 filepath,
256 custom_objects=custom_objects,
257 compile=compile,
258 safe_mode=safe_mode,
259 )
261 # Legacy case.
--> 262 return legacy_sm_saving_lib.load_model(
263 filepath, custom_objects=custom_objects, compile=compile, **kwargs
264 )

File /usr/local/lib/python3.11/dist-packages/keras/src/utils/traceback_utils.py:70, in filter_traceback..error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.traceback)
68 # To get the full stack trace, call:
69 # tf.debugging.disable_traceback_filtering()
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb

File /usr/local/lib/python3.11/dist-packages/keras/src/saving/legacy/serialization.py:365, in class_and_config_for_serialized_keras_object(config, module_objects, custom_objects, printable_module_name)
361 cls = object_registration.get_registered_object(
362 class_name, custom_objects, module_objects
363 )
364 if cls is None:
--> 365 raise ValueError(
366 f"Unknown {printable_module_name}: '{class_name}'. "
367 "Please ensure you are using a keras.utils.custom_object_scope "
368 "and that this object is included in the scope. See "
369 "https://www.tensorflow.org/guide/keras/save_and_serialize"
370 "#registering_the_custom_object for details."
371 )
373 cls_config = config["config"]
374 # Check if cls_config is a list. If it is a list, return the class and the
375 # associated class configs for recursively deserialization. This case will
376 # happen on the old version of sequential model (e.g. keras_version ==
377 # "2.0.6"), which is serialized in a different structure, for example
378 # "{'class_name': 'Sequential',
379 # 'config': [{'class_name': 'Embedding', 'config': ...}, {}, ...]}".

ValueError: Unknown optimizer: 'DPOptimizerClass'. Please ensure you are using a keras.utils.custom_object_scope and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions