tensorflow 梯度裁剪

gvs = optimizer.compute_gradients(loss) # 计算出梯度和变量值
capped_gvs = [(tf.clip_by_value(grad, -5e+10, 5e+10), var) for grad, var in gvs] # 梯度裁剪
train_op = optimizer.apply_gradients(capped_gvs, global_step=global_step) # 梯度下降

 

posted @ 2019-05-06 14:07  下路派出所  阅读(1290)  评论(0编辑  收藏  举报