Warning: This project is deprecated. TensorFlow Addons has stopped development, The project will only be providing minimal maintenance releases until May 2024. See the full announcement here or on github.

TensorFlow 的额外功能,由 SIG-addons 维护。

import tensorflow as tf
import tensorflow_addons as tfa
train,test = tf.keras.datasets.mnist.load_data()
x_train, y_train = train
x_train = x_train[..., tf.newaxis] / 255.0

# TFA layers and activations
model = tf.keras.Sequential([
  tf.keras.layers.Conv2D(filters=10, kernel_size=(3,3),
                         activation=tfa.activations.gelu),
  tfa.layers.GroupNormalization(groups=5, axis=3),
  tf.keras.layers.Flatten(),
  tf.keras.layers.Dense(10, activation='softmax')
])

# TFA optimizers, losses and metrics
model.compile(
    optimizer=tfa.optimizers.RectifiedAdam(0.001),
    loss=tfa.losses.TripletSemiHardLoss(),
    metrics=[tfa.metrics.MultiLabelConfusionMatrix(num_classes=10)])

history = model.fit(x_train, y_train, epochs=10)

TensorFlow SIG Addons 是包含社区贡献的代码库,它符合既定的 API 模式,但实现了核心 TensorFlow 中不具备的新功能。

TensorFlow 本身支持大量的运算符、层、指标、损失函数和优化器等。然而,在像机器学习这样的快速发展的领域,有很多有趣的新开发技术无法集成到核心 TensorFlow 中(因为它们能否广泛应用尚不明确,或者主要由社区中的少数人群使用)。