tf.data.experimental.Reducer
Редьюсер используется для свёртки набора элементов.
tf.data.experimental.Reducer(
init_func, reduce_func, finalize_func
)
Редьюсер представлен в виде кортежа из трёх функций:
- init_func — определяет начальное значение: key => initial state
- reducer_func — выполняет операцию над значениями с одинаковым ключом: (old state, input) => new state
- finalize_func — задаёт значение, возвращаемое в конце: state => result
Например,
def init_func(_): return (0.0, 0.0) def reduce_func(state, value): return (state[0] + value['features'], state[1] + 1) def finalize_func(s, n): return s / n reducer = tf.data.experimental.Reducer(init_func, reduce_func, finalize_func)
| Атрибуты | |
|---|---|
finalize_func | |
init_func | |
reduce_func | |
© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/data/experimental/Reducer