Adding reuse to training variables in tensorflow
up vote
0
down vote
favorite
I'm new to tensorflow but trying to run an older script that was uploaded to github. At the moment I'm stuck because tensorflow is trying to use a variable that already exists and I can't figure out where to add reuse. Any thoughts / suggestions would be really helpful! Thanks!
Code:
self.t_vars = tf.trainable_variables()
self.q_vars = [var for var in self.t_vars if (self.model_name+'_q_') in var.name]
self.g_vars = [var for var in self.t_vars if (self.model_name+'_g_') in var.name]
self.d_vars = [var for var in self.t_vars if (self.model_name+'_d_') in var.name]
self.both_vars = self.q_vars+self.g_vars
#self.vae_vars = self.q_vars # in this version, g_vars don't concern vae_loss
# clip gradients
d_opt_real_grads, _ = tf.clip_by_global_norm(tf.gradients(self.d_loss_real, self.d_vars), self.grad_clip)
d_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.d_loss, self.d_vars), self.grad_clip)
g_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.balanced_loss, self.both_vars), self.grad_clip)
vae_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.vae_loss, self.q_vars), self.grad_clip)
d_real_optimizer = tf.train.AdamOptimizer(self.learning_rate_d, beta1=self.beta1)
d_optimizer = tf.train.AdamOptimizer(self.learning_rate_d, beta1=self.beta1)
g_optimizer = tf.train.AdamOptimizer(self.learning_rate_g, beta1=self.beta1)
vae_optimizer = tf.train.AdamOptimizer(self.learning_rate_vae, beta1=self.beta1)
self.d_opt_real = d_real_optimizer.apply_gradients(zip(d_opt_real_grads, self.d_vars))
self.d_opt = d_optimizer.apply_gradients(zip(d_opt_grads, self.d_vars))
self.g_opt = g_optimizer.apply_gradients(zip(g_opt_grads, self.both_vars))
self.vae_opt = vae_optimizer.apply_gradients(zip(vae_opt_grads, self.q_vars))
Error:
ValueError: Variable cppnvae_d_h0_conv/w/Adam/ already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?
python tensorflow
add a comment |
up vote
0
down vote
favorite
I'm new to tensorflow but trying to run an older script that was uploaded to github. At the moment I'm stuck because tensorflow is trying to use a variable that already exists and I can't figure out where to add reuse. Any thoughts / suggestions would be really helpful! Thanks!
Code:
self.t_vars = tf.trainable_variables()
self.q_vars = [var for var in self.t_vars if (self.model_name+'_q_') in var.name]
self.g_vars = [var for var in self.t_vars if (self.model_name+'_g_') in var.name]
self.d_vars = [var for var in self.t_vars if (self.model_name+'_d_') in var.name]
self.both_vars = self.q_vars+self.g_vars
#self.vae_vars = self.q_vars # in this version, g_vars don't concern vae_loss
# clip gradients
d_opt_real_grads, _ = tf.clip_by_global_norm(tf.gradients(self.d_loss_real, self.d_vars), self.grad_clip)
d_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.d_loss, self.d_vars), self.grad_clip)
g_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.balanced_loss, self.both_vars), self.grad_clip)
vae_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.vae_loss, self.q_vars), self.grad_clip)
d_real_optimizer = tf.train.AdamOptimizer(self.learning_rate_d, beta1=self.beta1)
d_optimizer = tf.train.AdamOptimizer(self.learning_rate_d, beta1=self.beta1)
g_optimizer = tf.train.AdamOptimizer(self.learning_rate_g, beta1=self.beta1)
vae_optimizer = tf.train.AdamOptimizer(self.learning_rate_vae, beta1=self.beta1)
self.d_opt_real = d_real_optimizer.apply_gradients(zip(d_opt_real_grads, self.d_vars))
self.d_opt = d_optimizer.apply_gradients(zip(d_opt_grads, self.d_vars))
self.g_opt = g_optimizer.apply_gradients(zip(g_opt_grads, self.both_vars))
self.vae_opt = vae_optimizer.apply_gradients(zip(vae_opt_grads, self.q_vars))
Error:
ValueError: Variable cppnvae_d_h0_conv/w/Adam/ already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?
python tensorflow
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm new to tensorflow but trying to run an older script that was uploaded to github. At the moment I'm stuck because tensorflow is trying to use a variable that already exists and I can't figure out where to add reuse. Any thoughts / suggestions would be really helpful! Thanks!
Code:
self.t_vars = tf.trainable_variables()
self.q_vars = [var for var in self.t_vars if (self.model_name+'_q_') in var.name]
self.g_vars = [var for var in self.t_vars if (self.model_name+'_g_') in var.name]
self.d_vars = [var for var in self.t_vars if (self.model_name+'_d_') in var.name]
self.both_vars = self.q_vars+self.g_vars
#self.vae_vars = self.q_vars # in this version, g_vars don't concern vae_loss
# clip gradients
d_opt_real_grads, _ = tf.clip_by_global_norm(tf.gradients(self.d_loss_real, self.d_vars), self.grad_clip)
d_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.d_loss, self.d_vars), self.grad_clip)
g_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.balanced_loss, self.both_vars), self.grad_clip)
vae_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.vae_loss, self.q_vars), self.grad_clip)
d_real_optimizer = tf.train.AdamOptimizer(self.learning_rate_d, beta1=self.beta1)
d_optimizer = tf.train.AdamOptimizer(self.learning_rate_d, beta1=self.beta1)
g_optimizer = tf.train.AdamOptimizer(self.learning_rate_g, beta1=self.beta1)
vae_optimizer = tf.train.AdamOptimizer(self.learning_rate_vae, beta1=self.beta1)
self.d_opt_real = d_real_optimizer.apply_gradients(zip(d_opt_real_grads, self.d_vars))
self.d_opt = d_optimizer.apply_gradients(zip(d_opt_grads, self.d_vars))
self.g_opt = g_optimizer.apply_gradients(zip(g_opt_grads, self.both_vars))
self.vae_opt = vae_optimizer.apply_gradients(zip(vae_opt_grads, self.q_vars))
Error:
ValueError: Variable cppnvae_d_h0_conv/w/Adam/ already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?
python tensorflow
I'm new to tensorflow but trying to run an older script that was uploaded to github. At the moment I'm stuck because tensorflow is trying to use a variable that already exists and I can't figure out where to add reuse. Any thoughts / suggestions would be really helpful! Thanks!
Code:
self.t_vars = tf.trainable_variables()
self.q_vars = [var for var in self.t_vars if (self.model_name+'_q_') in var.name]
self.g_vars = [var for var in self.t_vars if (self.model_name+'_g_') in var.name]
self.d_vars = [var for var in self.t_vars if (self.model_name+'_d_') in var.name]
self.both_vars = self.q_vars+self.g_vars
#self.vae_vars = self.q_vars # in this version, g_vars don't concern vae_loss
# clip gradients
d_opt_real_grads, _ = tf.clip_by_global_norm(tf.gradients(self.d_loss_real, self.d_vars), self.grad_clip)
d_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.d_loss, self.d_vars), self.grad_clip)
g_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.balanced_loss, self.both_vars), self.grad_clip)
vae_opt_grads, _ = tf.clip_by_global_norm(tf.gradients(self.vae_loss, self.q_vars), self.grad_clip)
d_real_optimizer = tf.train.AdamOptimizer(self.learning_rate_d, beta1=self.beta1)
d_optimizer = tf.train.AdamOptimizer(self.learning_rate_d, beta1=self.beta1)
g_optimizer = tf.train.AdamOptimizer(self.learning_rate_g, beta1=self.beta1)
vae_optimizer = tf.train.AdamOptimizer(self.learning_rate_vae, beta1=self.beta1)
self.d_opt_real = d_real_optimizer.apply_gradients(zip(d_opt_real_grads, self.d_vars))
self.d_opt = d_optimizer.apply_gradients(zip(d_opt_grads, self.d_vars))
self.g_opt = g_optimizer.apply_gradients(zip(g_opt_grads, self.both_vars))
self.vae_opt = vae_optimizer.apply_gradients(zip(vae_opt_grads, self.q_vars))
Error:
ValueError: Variable cppnvae_d_h0_conv/w/Adam/ already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?
python tensorflow
python tensorflow
asked Nov 19 at 11:48
bwjames
11
11
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374013%2fadding-reuse-to-training-variables-in-tensorflow%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown