tensorflow - 是否可以在 TensorFlow 2 中使用 TensorFlow 1 模型?
问题描述
例如,某些模型已经使用 TensorFlow 1 架构进行了预训练。是否可以在 TensorFlow 2 中加载这个 TensorFlow 1 模型tf.keras.models.load_model(...)
?
解决方案
为了在 tensorflow v2 中使用 tensorflow v1 模型,您需要将兼容性模块导入为tf.compat.v1
并通过以下方式禁用 tensorflow v2 行为tf.compat.v1.disable_v2_behavior()
您可以通过以下方式加载版本 1 模型检查点:
with tf.Session() as sess:
# Restore variables from disk.
saver.restore(sess, "/tmp/model.ckpt")
至于以这种方式使用检查点,您需要使用训练代码转换模型,因为SavedModel
这是在 tensorflow v2 中使用的正确格式。
推荐阅读
- python - 切换第二个矩阵的列索引,直到与第一个矩阵的最高匹配(二进制值)
- python - TypeError:make_csv_dataset_v2() 为参数“column_names”获得了多个值
- xml - 雪花 xml 解析帮助不同的节点可以有 0 个重复的子节点
- python - 从表中删除行,但根据项目数创建行的索引
- azure - SAP 与 Azure 逻辑应用程序的集成 - 缓存/元数据问题?
- angular - 使用打字稿直接打印到带有pdf-to-printer的打印机
- c++ - 顶点缓冲区未正确清除
- r - 是否可以将反应值返回到主服务器?
- blockchain - 如何从 2 个 Urls 获取中值数据
- javascript - 使用Javascript将对象数组排序为配对对象数组