加载预训练的模型会引发ValueError:不良元帅数据(未知类型代码)

时间:2020-07-31 07:57:35

标签: python tensorflow keras google-colaboratory

File "train.py", line 43, in <module>
    FR=FR_model()
  File "/home/arsh/Desktop/machine learning/Outlier_dataset/Face_recognition.py", line 19, in __init__
    self.model = load_model('Facenet/facenet_model.h5')
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/saving/save.py", line 184, in load_model
    return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 177, in load_model_from_hdf5
    model = model_config_lib.model_from_config(model_config,
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/saving/model_config.py", line 55, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/layers/serialization.py", line 105, in deserialize
    return deserialize_keras_object(
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 369, in deserialize_keras_object
    return cls.from_config(
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/engine/network.py", line 986, in from_config
    input_tensors, output_tensors, created_layers = reconstruct_from_config(
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/engine/network.py", line 2019, in reconstruct_from_config
    process_layer(layer_data)
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/engine/network.py", line 2001, in process_layer
    layer = deserialize_layer(layer_data, custom_objects=custom_objects)
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/layers/serialization.py", line 105, in deserialize
    return deserialize_keras_object(
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 369, in deserialize_keras_object
    return cls.from_config(
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/layers/core.py", line 990, in from_config
    function = cls._parse_function_from_config(
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/layers/core.py", line 1042, in _parse_function_from_config
    function = generic_utils.func_load(
  File "/home/arsh/.virtualenvs/conditional_slim_gan/lib/python3.8/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 471, in func_load
    code = marshal.loads(raw_code)
ValueError: bad marshal data (unknown type code)

我正在尝试使用以下代码从 .h5 文件中加载预先训练的keras模型: self.model = load_model('Facenet/facenet_model.h5')

该代码在google colab上可以顺利运行,但是当我在本地运行它时,即使我的tensorflow和keras是最新的,它也会引发上述错误。

要重现该错误,请导航至my github存储库上的 Face_recognition.py

1 个答案:

答案 0 :(得分:0)

如果您查看generic_utils.py的源代码:

https://github.com/keras-team/keras/blob/master/keras/utils/generic_utils.py

您会看到没有471行,因此您似乎正在运行一些旧的keras实例,并且可能与使用较新(或完全不同)版本的数据不兼容。