【问题标题】:Get list of Keras variables获取 Keras 变量列表
【发布时间】:2018-10-30 17:56:34
【问题描述】:

我想将 Keras 模型中的变量与 TensorFlow 检查点中的变量进行比较。我可以像这样得到 TF 变量:

vars_in_checkpoint = tf.train.list_variables(os.path.join("./model.ckpt"))

如何从我的model 中获取要比较的 Keras 变量?

【问题讨论】:

    标签: python-3.x tensorflow keras


    【解决方案1】:

    您可以通过model.weightstf.Variable 实例列表)获取 Keras 模型的变量。

    【讨论】:

      【解决方案2】:

      要获取变量的名称,您需要从模型层的权重属性访问它。像这样的:

      names = [weight.name for layer in model.layers for weight in layer.weights]

      并得到重量的形状:

      weights = [weight.shape for weight in model.get_weights()]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-27
        • 2021-08-27
        • 1970-01-01
        • 1970-01-01
        • 2014-06-14
        • 2013-04-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多