首页 > 解决方案 > 在 Tensorflow 2.x 中访问和微调 Tensorflow 1.x 模型(架构和变量)

问题描述

我使用生成已知四个文件(.data、.meta、ckpt、.index)的 Tensorflow 1.x 保存了经过训练的模型。我想在 Tensorflow 2.x 中加载模型并将其用于对我自己的数据集进行微调。下面是我用来访问 1.x 模型的代码。

import tensorflow as tf
tf.compat.v1.disable_eager_execution()

session = tf.compat.v1.Session()
saver = tf.compat.v1.train.import_meta_graph('NameOfModel.meta')
saver.restore(session,tf.train.latest_checkpoint('./'))

graph = tf.compat.v1.get_default_graph() 

访问模型中的变量:

list_of_variables = tf.compat.v1.trainable_variables()

转换到 Tensorflow 2.x/Keras 以查看模型架构/摘要、继续训练和预测新数据集上的值的最简单方法是什么?

标签: pythontensorflowdeep-learningtensorflow2.0tensorflow1.15

解决方案


推荐阅读