TensorFlow SavedModel导出失败并出现AttributeError

时间:2019-11-23 18:23:38

标签: python tensorflow keras

我完全按照此处的说明进行操作:https://www.tensorflow.org/tutorials/keras/text_classification_with_hub

最后,如果我想使用model.save()从本教程中导出经过训练的模型,则会收到以下错误消息:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-19-768eb5acd4e8> in <module>()
      3 
      4 export_path = "/tmp/saved_models/{}".format(int(t))
----> 5 model.save(export_path, save_format='tf')

4 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/network.py in save(self, filepath, overwrite, include_optimizer, save_format, signatures, options)
    984     """
    985     saving.save_model(self, filepath, overwrite, include_optimizer, save_format,
--> 986                       signatures, options)
    987 
    988   def save_weights(self, filepath, overwrite=True, save_format=None):

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/save.py in save_model(model, filepath, overwrite, include_optimizer, save_format, signatures, options)
    113   else:
    114     saved_model_save.save(model, filepath, overwrite, include_optimizer,
--> 115                           signatures, options)
    116 
    117 

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/saved_model/save.py in save(model, filepath, overwrite, include_optimizer, signatures, options)
     72   # default learning phase placeholder.
     73   with K.learning_phase_scope(0):
---> 74     save_lib.save(model, filepath, signatures, options)
     75 
     76   if not include_optimizer:

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/saved_model/save.py in save(obj, export_dir, signatures, options)
    905   # Note we run this twice since, while constructing the view the first time
    906   # there can be side effects of creating variables.
--> 907   _ = _SaveableView(checkpoint_graph_view)
    908   saveable_view = _SaveableView(checkpoint_graph_view)
    909 

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/saved_model/save.py in __init__(self, checkpoint_view)
    189           concrete_functions = [function]
    190         for concrete_function in concrete_functions:
--> 191           if concrete_function.name not in seen_function_names:
    192             seen_function_names.add(concrete_function.name)
    193             self.concrete_functions.append(concrete_function)

AttributeError: 'NoneType' object has no attribute 'name'

这是怎么回事?不能简单地将此模型导出为SavedModel格式吗?

0 个答案:

没有答案