【问题标题】:Recording weight norm during training with TensorFlow 2使用 TensorFlow 2 在训练期间记录权重规范
【发布时间】:2021-03-05 18:52:33
【问题描述】:

我正在使用 tensorflow 训练一个神经网络,我想监控一些层的 L2 范数。 我在 tensorflow 1 中找到了如何做到这一点,例如 here,但我在 tensorflow 2 中找不到同样的方法。我想知道我该怎么做。谢谢!

【问题讨论】:

    标签: python tensorflow tensorflow2.x


    【解决方案1】:

    Tensorflow 2 提供了 Tensorflow 1 的兼容版本。 请找到以下用于计算非零权重的代码

    import tensorflow as tf
    import numpy as np
    
    #Replace tf.trainable_variables() with tf.compat.v1.trainable_variables
    tvars = tf.compat.v1.trainable_variables()
    nonzero_parameters = np.sum([np.count_nonzero(var) for var in tvars])
    

    【讨论】:

      猜你喜欢
      • 2018-07-28
      • 2021-03-28
      • 1970-01-01
      • 2020-03-15
      • 1970-01-01
      • 2016-02-23
      • 1970-01-01
      • 2019-11-29
      • 2018-07-13
      相关资源
      最近更新 更多