保存/加载子类模型tf2 + / keras

时间:2020-06-12 00:19:02

标签: python-3.x tensorflow keras

保存子类模型并重新加载它时,我遇到很多困难。我已将当前正在处理的文件(特别是policy.py)上传到https://github.com/ryanmaxwell96/trpo_fractal5NN。现在,我知道您应该能够以SavedModel格式保存内容,这就是我一直在尝试的方法。但我仍然收到此错误:

    Traceback (most recent call last):
  File "train.py", line 411, in <module>
    main(**vars(args))
  File "train.py", line 367, in main
    policy_model.save('policy_model')
  File "/home/ryan/.local/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/network.py", line 975, in save
    signatures, options)
  File "/home/ryan/.local/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/save.py", line 115, in save_model
    signatures, options)
  File "/home/ryan/.local/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/saved_model/save.py", line 74, in save
    save_lib.save(model, filepath, signatures, options)
  File "/home/ryan/.local/lib/python3.6/site-packages/tensorflow_core/python/saved_model/save.py", line 883, in save
    _ = _SaveableView(checkpoint_graph_view)
  File "/home/ryan/.local/lib/python3.6/site-packages/tensorflow_core/python/saved_model/save.py", line 164, in __init__
    self.checkpoint_view.objects_ids_and_slot_variables())
  File "/home/ryan/.local/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/graph_view.py", line 418, in objects_ids_and_slot_variables
    object_names[obj] = _object_prefix_from_path(path)
  File "/home/ryan/.local/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/graph_view.py", line 64, in _object_prefix_from_path
    for trackable in path_to_root))
  File "/home/ryan/.local/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/graph_view.py", line 64, in <genexpr>
    for trackable in path_to_root))
  File "/home/ryan/.local/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/graph_view.py", line 57, in _escape_local_name
    return (name.replace(_ESCAPE_CHAR, _ESCAPE_CHAR + _ESCAPE_CHAR)
AttributeError: 'NoneType' object has no attribute 'replace'

在policy.py文件的第90行中,我试图在调用train_on_batch和predict_on_batch之后保存子类模型“ self.trpo”。我完全不知道错误告诉我什么。

任何帮助将不胜感激!

谢谢

瑞安

0 个答案:

没有答案