Загрузка сохраненной модели BertClassifer - PullRequest
0 голосов
/ 16 июня 2020

Я использую следующий пример из этого блокнота colab: https://github.com/tensorflow/models/blob/master/official/colab/fine_tuning_bert.ipynb

Он сохраняет настроенную модель с помощью функции model.save ().

Я пытаюсь загрузить ту же модель с помощью tf.keras.models.load_model (), но получаю следующую ошибку:

KeyError: 'name'
KeyError                                  Traceback (most recent call last)
in engine
----> 1 model = tf.keras.models.load_model('./saved_model/test')

/home/cdsw/.local/lib/python3.6/site-packages/tensorflow/python/keras/saving/save.py in load_model(filepath, custom_objects, compile)
    183     if isinstance(filepath, six.string_types):
    184       loader_impl.parse_saved_model(filepath)
--> 185       return saved_model_load.load(filepath, compile)
    186 
    187   raise IOError(

/home/cdsw/.local/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in load(path, compile)
    114   # TODO(kathywu): Add saving/loading of optimizer, compiled losses and metrics.
    115   # TODO(kathywu): Add code to load from objects that contain all endpoints
--> 116   model = tf_load.load_internal(path, loader_cls=KerasObjectLoader)
    117 
    118   # pylint: disable=protected-access

/home/cdsw/.local/lib/python3.6/site-packages/tensorflow/python/saved_model/load.py in load_internal(export_dir, tags, loader_cls)
    605       loader = loader_cls(object_graph_proto,
    606                           saved_model_proto,
--> 607                           export_dir)
    608       root = loader.get(0)
    609       if isinstance(loader, Loader):

/home/cdsw/.local/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in __init__(self, *args, **kwargs)
    186     self._models_to_reconstruct = []
    187 
--> 188     super(KerasObjectLoader, self).__init__(*args, **kwargs)
    189 
    190     # Now that the node object has been fully loaded, and the checkpoint has

/home/cdsw/.local/lib/python3.6/site-packages/tensorflow/python/saved_model/load.py in __init__(self, object_graph_proto, saved_model_proto, export_dir)
    121       self._concrete_functions[name] = _WrapperFunction(concrete_function)
    122 
--> 123     self._load_all()
    124     self._restore_checkpoint()
    125 

/home/cdsw/.local/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in _load_all(self)
    207     # loaded from config may create variables / other objects during
    208     # initialization. These are recorded in `_nodes_recreated_from_config`.
--> 209     self._layer_nodes = self._load_layers()
    210 
    211     # Load all other nodes and functions.

/home/cdsw/.local/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in _load_layers(self)
    307         continue
    308 
--> 309       layers[node_id] = self._load_layer(proto.user_object, node_id)
    310 
    311     for node_id, proto in metric_list:

/home/cdsw/.local/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in _load_layer(self, proto, node_id)
    333     # Detect whether this object can be revived from the config. If not, then
    334     # revive from the SavedModel instead.
--> 335     obj, setter = self._revive_from_config(proto.identifier, metadata, node_id)
    336     if obj is None:
    337       obj, setter = revive_custom_object(proto.identifier, metadata)

/home/cdsw/.local/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in _revive_from_config(self, identifier, metadata, node_id)
    350     else:
    351       obj = (
--> 352           self._revive_graph_network(metadata, node_id) or
    353           self._revive_layer_from_config(metadata, node_id))
    354 

/home/cdsw/.local/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in _revive_graph_network(self, metadata, node_id)
    386     else:
    387       model = models_lib.Functional(
--> 388           inputs=[], outputs=[], name=config['name'])
    389 
    390     # Record this model and its layers. This will later be used to reconstruct

KeyError: 'name'

Может кто-нибудь посоветовать, что я делаю неправильно или должен ли я делать что еще загрузить эту модель? Спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...