Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,3 @@ wheels/
/.bazelrc
/bazel-*
/artifacts

# Addons
/docs/
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ let us give you advice on the proposed changes. If the changes are
minor, then feel free to make them without discussion.

Want to contribute but not sure of what? Here are a few suggestions:
1. Add a new example or tutorial. Located in [`examples/`](examples),
1. Add a new tutorial. Located in [`docs/tutorials/`](docs/tutorials),
these are a great way to familiarize yourself and others with TF-Addons. See
[the guidelines](examples/README.md) for more information on how to add
[the guidelines](docs/tutorials/README.md) for more information on how to add
examples.
2. Solve an [existing issue](https://github.com/tensorflow/addons/issues).
These range from low-level software bugs to higher-level design problems.
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
recursive-include tensorflow_addons/ *.so
include docs/*
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ bazel-bin/build_pip_pkg artifacts
pip install artifacts/tensorflow_addons-*.whl
```

## Examples
See [`examples/`](examples/)
## Tutorials
See [`docs/tutorials/`](docs/tutorials/)
for end-to-end examples of various addons.

## Core Concepts
Expand Down
46 changes: 46 additions & 0 deletions docs/_book.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ==============================================================================
upper_tabs:
# Tabs left of dropdown menu
- include: /_upper_tabs_left.yaml
- include: /api_docs/_upper_tabs_api.yaml
# Dropdown menu
- name: Resources
path: /resources
is_default: true
menu:
- include: /resources/_menu_toc.yaml
lower_tabs:
# Subsite tabs
other:
- name: tutorials
contents:
- title: Triplet loss
path: /addons/tutorials/losses_triplet
- title: Image Ops
path: /addons/tutorials/image_ops
- title: Normalization layers
path: /addons/tutorials/layers_normalizations
- title: Weight normalization layer
path: /addons/tutorials/layers_weightnormalization
- title: Lazyadam optimizer
path: /addons/tutorials/optimizers_lazyadam
- name: API
skip_translation: true
contents:
- include: /addons/api_docs/python/_toc.yaml

- include: /_upper_tabs_right.yaml
77 changes: 77 additions & 0 deletions docs/_index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ==============================================================================
book_path: /addons/_book.yaml
project_path: /addons/_project.yaml
description: <!--no description-->
landing_page:
custom_css_path: /site-assets/css/style.css
rows:
- heading: TensorFlow Addons provides useful extra functionality for TensorFlow 2.0 maintained by SIG-addons
items:
- classname: devsite-landing-row-50
description: >
TensorFlow Addons is a repository of contributions that conform to
well-established API patterns, but implement new functionality
not available in core TensorFlow. TensorFlow natively supports
a large number of operators, layers, metrics, losses, and
optimizers. However, in a fast moving field like ML, there are many
interesting new developments that cannot be integrated into core
TensorFlow (because their broad applicability is not yet clear, or
it is mostly used by a smaller subset of the community).
code_block: |
<pre class = "prettyprint">
import tensorflow as tf
import tensorflow_addons as tfa

# Load MNIST dataset as NumPy arrays
dataset = {}
num_validation = 10000
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()

# Preprocess the data
x_train = x_train.reshape(-1, 784).astype('float32') / 255
x_test = x_test.reshape(-1, 784).astype('float32') / 255

# Compile the model
model.compile(
optimizer=tfa.optimizers.LazyAdam(0.001), # Utilize TFA optimizer
loss=tf.keras.losses.SparseCategoricalCrossentropy(),
metrics=['accuracy'])

# Train the network
history = model.fit(
x_train,
y_train,
batch_size=24,
epochs=10)
</pre>
{% dynamic if request.tld != 'cn' %}
<a class="colab-button" target="_blank" href="https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/optimizers_lazyadam.ipynb">Run in a <span>Notebook</span></a>
{% dynamic endif %}
- classname: devsite-landing-row-cards
items:
- heading: "Introducing TensorFlow Addons"
image_path: /resources/images/tf-logo-card-16x9.png
path: https://medium.com/tensorflow/introducing-tensorflow-addons-6131a50a3dcf
buttons:
- label: "Read on TensorFlow blog"
path: https://medium.com/tensorflow/introducing-tensorflow-addons-6131a50a3dcf
- heading: "TensorFlow Addons on GitHub"
image_path: /resources/images/github-card-16x9.png
path: https://github.com/tensorflow/addons
buttons:
- label: "View on GitHub"
path: https://github.com/tensorflow/addons
26 changes: 26 additions & 0 deletions docs/_project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ==============================================================================
name: TensorFlow Addons
breadcrumb_name: Addons
home_url: /addons/
parent_project_metadata_path: /_project.yaml
description: >
"TensorFlow Addons is a library of useful extra functionality for
TensorFlow 2.0 maintained by SIG-addons"
use_site_branding: true
hide_from_products_list: true
content_license: cc-apache
include: /_project_included.yaml
8 changes: 4 additions & 4 deletions examples/README.md → docs/tutorials/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# TensorFlow Addons Examples
# TensorFlow Addons Tutorials

TensorFlow Addons welcomes and highly encourages example contributions.
TensorFlow Addons welcomes and highly encourages tutorial contributions.


## How To Contribute

Addons examples are created using [Google Colab](https://colab.research.google.com/)
Addons tutorials are created using [Google Colab](https://colab.research.google.com/)
and the jupyter notebooks are saved to this directory in the repository. To do
this, follow the below steps:

1. Create a new branch on your fork of TensorFlow Addons
2. Goto [Google Colab](https://colab.research.google.com/) and start a new
notebook using addons example template:
[examples/template.ipynb](template.ipynb)
[docs/tutorials/template.ipynb](template.ipynb)
3. Edit the the links for the "View source on GitHub" and "Run in Google Colab"
URL boxes so that they match the name of your new example notebook
4. Follow the guidelines of the template
Expand Down
4 changes: 2 additions & 2 deletions examples/image_ops.ipynb → docs/tutorials/image_ops.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
"\n",
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/examples/image_ops.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/image_ops.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/examples/image_ops.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/docs/tutorials/image_ops.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
"</table>"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
"\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/examples/layers_normalizations.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/layers_normalizations.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/examples/layers_normalizations.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/docs/tutorials/layers_normalizations.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
"</table>\n"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
"\n",
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/examples/layers_weightnormalization.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/layers_weightnormalization.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/examples/layers_weightnormalizations.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/docs/tutorials/layers_weightnormalizations.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
"</table>"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
"\n",
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/examples/losses_triplet.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/losses_triplet.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/examples/losses_triplet.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/docs/tutorials/losses_triplet.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
"</table>"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
"\n",
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/examples/optimizers_lazyadam.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/optimizers_lazyadam.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/examples/optimizers_lazyadam.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/docs/tutorials/optimizers_lazyadam.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
"</table>"
]
Expand Down
4 changes: 2 additions & 2 deletions examples/template.ipynb → docs/tutorials/template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
"source": [
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/examples/template.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/addons/blob/master/docs/tutorials/template.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/examples/template.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/addons/blob/master/docs/tutorials/template.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
"</table>"
]
Expand Down
8 changes: 4 additions & 4 deletions tensorflow_addons/activations/gelu.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def gelu(x, approximate=True):
A `Tensor`. Has the same type as `x`.
"""
x = tf.convert_to_tensor(x)
return _activation_ops_so.gelu(x, approximate)
return _activation_ops_so.addons_gelu(x, approximate)


@tf.RegisterGradient("Gelu")
@tf.RegisterGradient("Addons>Gelu")
def _gelu_grad(op, grad):
return _activation_ops_so.gelu_grad(grad, op.inputs[0],
op.get_attr("approximate"))
return _activation_ops_so.addons_gelu_grad(grad, op.inputs[0],
op.get_attr("approximate"))
10 changes: 5 additions & 5 deletions tensorflow_addons/activations/hardshrink.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def hardshrink(x, lower=-1.0, upper=1.0):
A `Tensor`. Has the same type as `x`.
"""
x = tf.convert_to_tensor(x)
return _activation_ops_so.hardshrink(x, lower, upper)
return _activation_ops_so.addons_hardshrink(x, lower, upper)


@tf.RegisterGradient("Hardshrink")
@tf.RegisterGradient("Addons>Hardshrink")
def _hardshrink_grad(op, grad):
return _activation_ops_so.hardshrink_grad(grad, op.inputs[0],
op.get_attr("lower"),
op.get_attr("upper"))
return _activation_ops_so.addons_hardshrink_grad(grad, op.inputs[0],
op.get_attr("lower"),
op.get_attr("upper"))
28 changes: 15 additions & 13 deletions tensorflow_addons/custom_ops/activations/cc/kernels/gelu_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ limitations under the License.
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"

namespace tensorflow {
namespace addons {

using CPUDevice = Eigen::ThreadPoolDevice;

#define REGISTER_GELU_KERNELS(type) \
REGISTER_KERNEL_BUILDER( \
Name("Gelu").Device(DEVICE_CPU).TypeConstraint<type>("T"), \
GeluOp<CPUDevice, type>); \
REGISTER_KERNEL_BUILDER( \
Name("GeluGrad").Device(DEVICE_CPU).TypeConstraint<type>("T"), \
#define REGISTER_GELU_KERNELS(type) \
REGISTER_KERNEL_BUILDER( \
Name("Addons>Gelu").Device(DEVICE_CPU).TypeConstraint<type>("T"), \
GeluOp<CPUDevice, type>); \
REGISTER_KERNEL_BUILDER( \
Name("Addons>GeluGrad").Device(DEVICE_CPU).TypeConstraint<type>("T"), \
GeluGradOp<CPUDevice, type>);

// Gelu only makes sense with floating points.
Expand Down Expand Up @@ -61,17 +62,18 @@ TF_CALL_GPU_NUMBER_TYPES(DECLARE_GPU_SPEC);
} // namespace functor

// Registration of the GPU implementations.
#define REGISTER_GELU_GPU_KERNELS(type) \
REGISTER_KERNEL_BUILDER( \
Name("Gelu").Device(DEVICE_GPU).TypeConstraint<type>("T"), \
GeluOp<GPUDevice, type>); \
REGISTER_KERNEL_BUILDER( \
Name("GeluGrad").Device(DEVICE_GPU).TypeConstraint<type>("T"), \
#define REGISTER_GELU_GPU_KERNELS(type) \
REGISTER_KERNEL_BUILDER( \
Name("Addons>Gelu").Device(DEVICE_GPU).TypeConstraint<type>("T"), \
GeluOp<GPUDevice, type>); \
REGISTER_KERNEL_BUILDER( \
Name("Addons>GeluGrad").Device(DEVICE_GPU).TypeConstraint<type>("T"), \
GeluGradOp<GPUDevice, type>);

TF_CALL_GPU_NUMBER_TYPES(REGISTER_GELU_GPU_KERNELS);
#undef REGISTER_GELU_GPU_KERNELS

#endif // GOOGLE_CUDA

} // namespace tensorflow
} // end namespace addons
} // namespace tensorflow
Loading