tf.compat.v1.train.piecewise_constant
Stay organized with collections
Save and categorize content based on your preferences.
Piecewise constant from boundaries and interval values.
tf.compat.v1.train.piecewise_constant(
x, boundaries, values, name=None
)
Example: use a learning rate that's 1.0 for the first 100001 steps, 0.5
for the next 10000 steps, and 0.1 for any additional steps.
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.
Args |
x
|
A 0-D scalar Tensor . Must be one of the following types: float32 ,
float64 , uint8 , int8 , int16 , int32 , int64 .
|
boundaries
|
A list of Tensor s or int s or float s with strictly
increasing entries, and with all elements having the same type as x .
|
values
|
A list of Tensor s or float s or int s that specifies the values
for the intervals defined by boundaries . It should have one more element
than boundaries , and all elements should have the same type.
|
name
|
A string. Optional name of the operation. Defaults to
'PiecewiseConstant'.
|
Returns |
A 0-D Tensor. Its value is values[0] when x <= boundaries[0] ,
values[1] when x > boundaries[0] and x <= boundaries[1] , ...,
and values[-1] when x > boundaries[-1] .
|
Raises |
ValueError
|
if types of x and boundaries do not match, or types of all
values do not match or
the number of elements in the lists does not match.
|
When eager execution is enabled, this function returns a function which in
turn returns the decayed learning rate Tensor. This can be useful for changing
the learning rate value across different invocations of optimizer functions.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.compat.v1.train.piecewise_constant\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/keras/optimizer_v2/legacy_learning_rate_decay.py#L104-L182) |\n\nPiecewise constant from boundaries and interval values.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.train.piecewise_constant_decay`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/train/piecewise_constant)\n\n\u003cbr /\u003e\n\n tf.compat.v1.train.piecewise_constant(\n x, boundaries, values, name=None\n )\n\nExample: use a learning rate that's 1.0 for the first 100001 steps, 0.5\nfor the next 10000 steps, and 0.1 for any additional steps. \n\n global_step = tf.Variable(0, trainable=False)\n boundaries = [100000, 110000]\n values = [1.0, 0.5, 0.1]\n learning_rate = tf.compat.v1.train.piecewise_constant(global_step, boundaries,\n values)\n\n # Later, whenever we perform an optimization step, we increment global_step.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `x` | A 0-D scalar `Tensor`. Must be one of the following types: `float32`, `float64`, `uint8`, `int8`, `int16`, `int32`, `int64`. |\n| `boundaries` | A list of `Tensor`s or `int`s or `float`s with strictly increasing entries, and with all elements having the same type as `x`. |\n| `values` | A list of `Tensor`s or `float`s or `int`s that specifies the values for the intervals defined by `boundaries`. It should have one more element than `boundaries`, and all elements should have the same type. |\n| `name` | A string. Optional name of the operation. Defaults to 'PiecewiseConstant'. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A 0-D Tensor. Its value is `values[0]` when `x \u003c= boundaries[0]`, `values[1]` when `x \u003e boundaries[0]` and `x \u003c= boundaries[1]`, ..., and values\\[-1\\] when `x \u003e boundaries[-1]`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|---------------------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | if types of `x` and `boundaries` do not match, or types of all `values` do not match or the number of elements in the lists does not match. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\neager compatibility\n-------------------\n\n\u003cbr /\u003e\n\nWhen eager execution is enabled, this function returns a function which in\nturn returns the decayed learning rate Tensor. This can be useful for changing\nthe learning rate value across different invocations of optimizer functions.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]