tensorlayer / TensorLayer

Deep Learning and Reinforcement Learning Library for Scientists and Engineers
http://tensorlayerx.com
Other
7.33k stars 1.61k forks source link

What's the difference between network.all_params and tl.layers.get_variables_with_name('scope_name')? #138

Closed ryx19th closed 7 years ago

ryx19th commented 7 years ago

There seem two ways to get all parameters(called in TL)/variables(called in TF), one provided by TL is all_params, the other provided by TF (and wrapped by TL) is get_variables_with_name().

I wonder what the difference between them is? I did some trials and found they are not same. all_params is always larger because it contains moving_mean and moving_variance of many layers. But sometimes it can also leave some important variables, like beta and gemma in some batch normalization layers, though not all.

I want to know which I should use in the following situation and why:

  1. When I'm train a GAN, where I need to train the generator and discriminator separately, which should I use as the var_list in tf.train.Optimizer.minimize()?
  2. When I want to save a trained model to disk for future load, which should I use as the params in tl.files.save_npz()?

I know there is a DCGAN repo written in TL and get_variables_with_name() is choosed. As well in the doc it is said to choose all_params for tl.files.save_npz(). But what if I make a different choice? Actually these two situations don't differ too much in my opinion, but why the answers are not same?

Thank you.

zsdonghao commented 7 years ago

Hi, both are the same, because moving_mean and moving_variance are not trainable variable and only be used during training.

ryx19th commented 7 years ago

Oh thank you for the answer. It does make sense.