python - 如何将 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}
解决方案
推荐阅读
- ignite - Apache Ignite 集群节点未从外部数据库加载所有数据
- python - 在修饰函数中强制执行仅关键字参数
- vuejs2 - Vuejs2 axios 突变:更新一个对象
- assembly - 为什么编译器使用帧指针和链接寄存器?
- java - AWS EC2 Linux 2 上的 java FileNotFoundException 但文件在那里
- azure-active-directory - 从 Microsoft Graph Beta 端点查询 /policies/authenticationFlowsPolicy
- spring - 具有多个条件的 Spring 数据 MongoDB 地理空间查询
- magento2 - 如何在移动设备上使用具有不同行为的 magento x-magento-init 手风琴?
- c# - .NET 捆绑仅在服务器重新启动时引发错误
- r - 在 r 中求解 LPP