邊界和區間值的分段常數。
用法
tf.compat.v1.train.piecewise_constant(
x, boundaries, values, name=None
)
參數
-
x
一個 0-D 標量Tensor
。必須是以下類型之一:float32
,float64
,uint8
,int8
,int16
,int32
,int64
。 -
boundaries
Tensor
s 或int
s 或float
s 的列表具有嚴格增加的條目,並且所有元素具有與x
相同的類型。 -
values
Tensor
或float
或int
的列表,指定由boundaries
定義的間隔的值。它應該比boundaries
多一個元素,並且所有元素都應該具有相同的類型。 -
name
一個字符串。操作的可選名稱。默認為'PiecewiseConstant'。
返回
-
一個 0-D 張量。它的值為
values[0]
當x <= boundaries[0]
,values[1]
當x > boundaries[0]
和x <= boundaries[1]
,...,和 values[-1] 當x > boundaries[-1]
。
拋出
-
ValueError
如果x
和boundaries
的類型不匹配,或者所有values
的類型不匹配或者列表中的元素數量不匹配。
示例:前 100001 步使用 1.0,接下來 10000 步使用 0.5,任何其他步驟使用 0.1 的學習率。
global_step = tf.Variable(0, trainable=False)
boundaries = [100000, 110000]
values = [1.0, 0.5, 0.1]
learning_rate = tf.compat.v1.train.piecewise_constant(global_step, boundaries,
values)
# Later, whenever we perform an optimization step, we increment global_step.
eager模式兼容性
當啟用即刻執行時,此函數返回一個函數,該函數又返回衰減的學習率張量。這對於在優化器函數的不同調用中更改學習率值很有用。
相關用法
- Python tf.compat.v1.train.polynomial_decay用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.get_or_create_global_step用法及代碼示例
- Python tf.compat.v1.train.cosine_decay_restarts用法及代碼示例
- Python tf.compat.v1.train.Optimizer用法及代碼示例
- Python tf.compat.v1.train.AdagradOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.init_from_checkpoint用法及代碼示例
- Python tf.compat.v1.train.Checkpoint用法及代碼示例
- Python tf.compat.v1.train.Supervisor.managed_session用法及代碼示例
- Python tf.compat.v1.train.Checkpoint.restore用法及代碼示例
- Python tf.compat.v1.train.global_step用法及代碼示例
- Python tf.compat.v1.train.MonitoredSession.run_step_fn用法及代碼示例
- Python tf.compat.v1.train.RMSPropOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.exponential_decay用法及代碼示例
- Python tf.compat.v1.train.natural_exp_decay用法及代碼示例
- Python tf.compat.v1.train.MomentumOptimizer用法及代碼示例
- Python tf.compat.v1.train.RMSPropOptimizer用法及代碼示例
- Python tf.compat.v1.train.get_global_step用法及代碼示例
- Python tf.compat.v1.train.GradientDescentOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.train.linear_cosine_decay用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.train.piecewise_constant。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。