0

I am training a neural network using tensorflow and I would like to monitor the L2-norm of some of the layers. I found how to do this in tensorflow 1, for instance here, but I could not find a way to do the same in tensorflow 2. I wonder how can I do that. Thanks!

sstev3
  • 53
  • 5

1 Answers1

0

Tensorflow 2 provides compat version of Tensorflow 1. Please find the below code for computing nonzero weights

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])