python - 在 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 以查看模型架构/摘要、继续训练和预测新数据集上的值的最简单方法是什么?
解决方案
推荐阅读
- python - 根据键的值显示字典中最大的项目?
- laravel - Laravel / Voyager 创建事件未在用户模型中触发
- arrows - RBokeh 中的箭头
- ios - UIBarButtonItem 外观设置不同样式的titleTextAttributes
- c# - 兔MQ。等待下一条消息的最佳实践
- haskell - 按列表的第一个元素对列表进行分组
- spring - 在 J2EE 应用程序中集成 Angular 5
- javascript - 通过 displayName 找到的酶玩笑不起作用?
- ruby-on-rails - Ruby on Rails 中的 options_from_collection_for_select 问题
- c# - 如何在 WPF 中使用 EntityFramework 将数据绑定到 DataGridView