3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tf.clip_by_value

Posted at

はじめに

強化学習,DQNのモデルで使われていました

前提

Tensorflow1.8

Gradient Clippingについて

tensorflowでは以下のような行列の切り取りをするopsをいくつか提供しています.このような関数はデータの切り取りにも使えるし,よく勾配の発散や消失を防ぐことにも使われます.

  • tf.clip_by_value
  • tf.clip_by_norm
  • tf.clip_by_average_norm
  • tf.clip_by_global_norm
  • tf.global_norm

tf.clip_by_valueの定義

tf.clip_by_value(
    t,
    clip_value_min,
    clip_value_max,
    name=None
)

行列(t)を与えて,最小値(clip_value_min)と最大値(clip_value_max)を決め実行することで,その範囲外の値を切り取る.ここでの切り取るとは値を削除するという意味ではなくclip_value_max以上の値はclip_value_maxの値に,clip_value_min以下の値はclip_value_maxの値に修正するという意味である.

## 使い方確認

import tensorflow as tf

a = tf.clip_by_value([1,0.3,-10,0,2,0.4,6,],0.0,1.0)

sess = tf.Session()
a_result = sess.run(a)

print("length = {},\ntype = {}\nvalue = {}".format(len(a_result),type(a_result),a_result))
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?