Skip to content

Commit ebd9f41

Browse files
gabrieldemarmiesseseanpmorgan
authored andcommitted
Added types and typeguard. (#894)
* Added types and typeguard.
1 parent faaad90 commit ebd9f41

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

Diff for: requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
tf-nightly
1+
tf-nightly
2+
typeguard

Diff for: tensorflow_addons/layers/normalizations.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
import logging
1919
import tensorflow as tf
20+
from typeguard import typechecked
21+
22+
from tensorflow_addons.utils import types
2023

2124

2225
@tf.keras.utils.register_keras_serializable(package='Addons')
@@ -67,18 +70,19 @@ class GroupNormalization(tf.keras.layers.Layer):
6770
- [Group Normalization](https://arxiv.org/abs/1803.08494)
6871
"""
6972

73+
@typechecked
7074
def __init__(self,
71-
groups=2,
72-
axis=-1,
73-
epsilon=1e-3,
74-
center=True,
75-
scale=True,
76-
beta_initializer='zeros',
77-
gamma_initializer='ones',
78-
beta_regularizer=None,
79-
gamma_regularizer=None,
80-
beta_constraint=None,
81-
gamma_constraint=None,
75+
groups: int = 2,
76+
axis: int = -1,
77+
epsilon: int = 1e-3,
78+
center: bool = True,
79+
scale: bool = True,
80+
beta_initializer: types.Initializer = 'zeros',
81+
gamma_initializer: types.Initializer = 'ones',
82+
beta_regularizer: types.Regularizer = None,
83+
gamma_regularizer: types.Regularizer = None,
84+
beta_constraint: types.Constraint = None,
85+
gamma_constraint: types.Constraint = None,
8286
**kwargs):
8387
super().__init__(**kwargs)
8488
self.supports_masking = True

Diff for: tensorflow_addons/utils/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ py_library(
99
"keras_utils.py",
1010
"test_utils.py",
1111
"resource_loader.py",
12+
"types.py",
1213
]),
1314
)
1415

Diff for: tensorflow_addons/utils/types.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Types for typing functions signatures."""
16+
17+
from typing import Union, Callable
18+
19+
Initializer = Union[None, dict, str, Callable]
20+
Regularizer = Union[None, dict, str, Callable]
21+
Constraint = Union[None, dict, str, Callable]

0 commit comments

Comments
 (0)