首页 > 解决方案 > 如何将 tensorflow .pb 转换为 keras .h5?

问题描述

我正在尝试将文件(.pb)格式的模型转换为文件(.h5)格式。我尝试点击以下链接:Tensorflow (.pb) format to Keras (.h5)

下面是我写的代码:

import tensorflow as tf
import os
facenet_model = tf.keras.models.load_model('./model_data/20180402-114759/')
tf.keras.models.save_model(facenet_model, 'New_Model.h5') # Saving the Model in H5 Format
loaded_model_from_h5 = tf.keras.models.load_model('New_Model.h5') # Loading the H5 Saved Model
print(loaded_model_from_h5.summary())

除了20180402-114759.pb文件,如下截图所示: 在此处输入图像描述

这就是发生的事情:

Traceback (most recent call last):
  File "test_facenet.py", line 25, in <module>
    facenet_model = tf.keras.models.load_model('./model_data/20180402-114759/')
  File "C:\Users\hai.nguyendinhkhanh\.conda\envs\py36\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 146, in load_model
    loader_impl.parse_saved_model(filepath)
  File "C:\Users\hai.nguyendinhkhanh\.conda\envs\py36\lib\site-packages\tensorflow_core\python\saved_model\loader_impl.py", line 83, in parse_saved_model
    constants.SAVED_MODEL_FILENAME_PB))
OSError: SavedModel file does not exist at: ./model_data/20180402-114759//{saved_model.pbtxt|saved_model.pb}

标签: pythontensorflowkerasmodelartificial-intelligence

解决方案


推荐阅读