Any recommended way to save a tf privacy model?

未关闭
#559 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
python, tensorflow

调研方向

从报告中显示的 TensorFlow/Keras 保存和加载入口开始,包括 tf.saved_model.save 和 tf.keras.models.load_model。调查 DPOptimizerClass 反序列化失败的问题;确认一种受支持的保存并重新加载 TensorFlow Privacy 模型的方法,或记录一个修复方案,即可视为完成。

由索引模型根据 Issue 内容生成。

描述

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.`

主要语言
Python
星标
2k
派生
477
平均合并
17 小时 24 分钟
30 天内合并 PR
4

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tensorflow/privacy 的其他 Issue

查看 tensorflow/privacy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。