python-3.x - 无法使用更新代码在 tensorflow V2 中加载 TensorFlow v1 模型?
问题描述
我保存了 .ckpt 和 .h5 格式的模型,其中我的文件夹包含 4 个文件。
如果我使用命令加载版本 1
model.load("model.ckpt") or model.load("model.h5")
它在 Tensorflow 版本 1 中加载成功,但在 tensorflow 版本 2 中加载时显示错误
tf.keras.models.load_model('model.h5') or tf.keras.models.load_model('model.ckpt')
有时会出错
SavedModel file does not exist at: /model/model.ckpt/{saved_model.pbtxt|saved_model.pb}
或有时给出错误
OSError: Unable to open file (unable to open file: name = 'model.ckpt', errno = 2, error message =
'No such file or directory', flags = 0, o_flags = 0)
我仔细检查了我在 google colab 中上传的路径并给出了确切的位置,但没有工作。
这是我的代码链接
https://colab.research.google.com/drive/1hf7AwEMJHf4zLZOBSzxejA2ISuTQ3N9K
解决方案
If the file is inside a folder in your drive then add your folder's name in the path. otherwise use the code as it is.
import os
from google.colab import drive
drive.mount('/content/gdrive')
model_file_name = os.path.join("/content/gdrive/My Drive", 'model.h5')# CHANGE MODEL NAME
model = tf.keras.models.load_model(model_file_name)
On execution it will show a link click on it and choose your drive account where the file is located, then copy paste the key in your program.
推荐阅读
- python - Pygame 运动(机制):为什么我的玩家永远不会回到地面?
- php - 如何将 SQL 表中的所有行检索到数组中?
- java - 仅在您的班级之一完成测试后,如何以班级级别的并行性运行您的测试
- eclipse - 将eclipse安装迁移到另一台计算机的最佳方法
- azure - 将文件保存在 Azure 应用服务上并使其可从外部访问
- python - 如何绘制两个文档的两个向量之间的余弦角。(python中的余弦相似度概念)
- python - 坐标排序和按坐标位置分类,而不是按分数分类
- javascript - 获取 CORS 策略:没有“Access-Control-Allow-Origin”错误
- angular - 如何在子组件中使用角度动画
- python - Django-Filter FilterSet 仅显示用户生成的对象