python tensorflow clip_by_norm

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python tensorflow clip_by_norm相关的知识,希望对你有一定的参考价值。

"""Prepare to Train"""
global_step = tf.Variable(0, name="global_step", trainable=False)

variable_to_train = []
for variable in tf.trainable_variables():
  if not(variable.name.startswith(FLAGS.loss_model)):
      variable_to_train.append(variable)
# train_op = tf.train.AdamOptimizer(1e-3).minimize(loss, global_step=global_step, var_list=variable_to_train)
#...................
optimizer = tf.train.AdamOptimizer(1e-3)
gvs = optimizer.compute_gradients(loss, var_list=variable_to_train)
capped_gvs = [(tf.clip_by_norm(grad, 10), var) for grad, var in gvs]
train_op = optimizer.apply_gradients(capped_gvs, global_step=global_step)
#....................

以上是关于python tensorflow clip_by_norm的主要内容,如果未能解决你的问题,请参考以下文章

python tensorflow 学习

python [test tensorflow] test tensorflow installation #tensorflow

python 3.8 下安装 tensorflow 1.14

Ubuntu上安装TensorFlow(python2.7版)

python3 tensorflow 安装

ImportError:没有名为“tensorflow.python”的模块与 tensorflow-gpu