Skip to content

Commit

Permalink
[MNT] Removing tensorflow_addons dependency (#1421)
Browse files Browse the repository at this point in the history
* tensorflow bound

* add manually instance normalization

* empty commit

* fix doxs

* fix bug

* add maintainer

* re arrange

* dep on utils

* fix comments

* add version and file to header

* re add conflict

* remove addon

* only adodn remove

* add typeguard dep

* remove addons from test

* remove tag of python<3.12 from base class

* edit pyptoject for test details

* remove typeguard

* remove addons

* remove typeguard

* fix bug in python version

* remove config on python < 3.12

* remove python version from test

* remove python version from base

* use group norm

* re-add 3.12 limit

* remove tags and add python version

* skip random state clr test

* fix test all networks

* set y for channel selection test

* set y for channel selection test

---------

Co-authored-by: hadifawaz1999 <hadifawaz2291999@gmail.com>
Co-authored-by: Tony Bagnall <ajb@uea.ac.uk>
  • Loading branch information
3 people authored Jul 4, 2024
1 parent bc873d3 commit 1e08b19
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 19 deletions.
7 changes: 4 additions & 3 deletions aeon/classification/deep_learning/_encoder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Encoder Classifier."""

__maintainer__ = []
__maintainer__ = ["hadifawaz1999"]
__all__ = ["EncoderClassifier"]

import gc
Expand Down Expand Up @@ -83,7 +83,7 @@ class EncoderClassifier(BaseDeepClassifier):
"""

_tags = {
"python_dependencies": ["tensorflow", "tensorflow_addons"],
"python_dependencies": ["tensorflow"],
}

def __init__(
Expand Down Expand Up @@ -255,7 +255,8 @@ def _fit(self, X, y):

try:
self.model_ = tf.keras.models.load_model(
self.file_path + self.file_name_ + ".keras", compile=False
self.file_path + self.file_name_ + ".keras",
compile=False,
)
if not self.save_best_model:
os.remove(self.file_path + self.file_name_ + ".keras")
Expand Down
1 change: 0 additions & 1 deletion aeon/classification/deep_learning/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class BaseDeepClassifier(BaseClassifier, ABC):
"non-deterministic": True,
"cant-pickle": True,
"python_dependencies": "tensorflow",
"python_version": "<3.12",
}

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@pytest.mark.skipif(
not _check_soft_dependencies(["tensorflow", "tensorflow_addons"], severity="none"),
not _check_soft_dependencies(["tensorflow"], severity="none"),
reason="skip test if required soft dependency not available",
)
def test_random_state_deep_learning_cls():
Expand Down
1 change: 0 additions & 1 deletion aeon/clustering/deep_learning/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class BaseDeepClusterer(BaseClusterer, ABC):
"non-deterministic": True,
"cant-pickle": True,
"python_dependencies": "tensorflow",
"python_version": "<3.12",
}

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

from aeon.clustering import deep_learning
from aeon.testing.data_generation import make_example_3d_numpy
from aeon.utils.validation._dependencies import _check_soft_dependencies

__maintainer__ = ["hadifawaz1999"]


@pytest.mark.skipif(
not _check_soft_dependencies(["tensorflow", "tensorflow_addons"], severity="none"),
# not _check_soft_dependencies("tensorflow", severity="none"),
# See Issue #1761
True,
reason="skip test if required soft dependency not available",
)
def test_random_state_deep_learning_clr():
Expand Down
9 changes: 5 additions & 4 deletions aeon/networks/_encoder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Encoder Classifier."""

__maintainer__ = []
__maintainer__ = ["hadifawaz1999"]

from aeon.networks.base import BaseDeepLearningNetwork

Expand Down Expand Up @@ -88,7 +88,8 @@ def build_network(self, input_shape, **kwargs):
output_layer : a keras layer
"""
import tensorflow as tf
import tensorflow_addons as tfa

tf.keras.config.enable_unsafe_deserialization()

self._kernel_size = (
[5, 11, 21] if self.kernel_size is None else self.kernel_size
Expand All @@ -107,7 +108,7 @@ def build_network(self, input_shape, **kwargs):
strides=self.strides,
)(x)

conv = tfa.layers.InstanceNormalization()(conv)
conv = tf.keras.layers.GroupNormalization(groups=-1)(conv)
conv = tf.keras.layers.PReLU(shared_axes=[1])(conv)
conv = tf.keras.layers.Dropout(self.dropout_proba)(conv)

Expand Down Expand Up @@ -138,7 +139,7 @@ def build_network(self, input_shape, **kwargs):
hidden_fc_layer = tf.keras.layers.Dense(
units=self.fc_units, activation=self.activation
)(attention)
hidden_fc_layer = tfa.layers.InstanceNormalization()(hidden_fc_layer)
hidden_fc_layer = tf.keras.layers.GroupNormalization(groups=-1)(hidden_fc_layer)

# output layer before classification layer

Expand Down
2 changes: 1 addition & 1 deletion aeon/regression/deep_learning/_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class EncoderRegressor(BaseDeepRegressor):
"""

_tags = {
"python_dependencies": ["tensorflow", "tensorflow_addons"],
"python_dependencies": ["tensorflow"],
}

def __init__(
Expand Down
1 change: 0 additions & 1 deletion aeon/regression/deep_learning/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class BaseDeepRegressor(BaseRegressor, ABC):
"non-deterministic": True,
"cant-pickle": True,
"python_dependencies": "tensorflow",
"python_version": "<3.12",
}

def __init__(self, batch_size=40, last_file_name="last_model"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@pytest.mark.skipif(
not _check_soft_dependencies(["tensorflow", "tensorflow_addons"], severity="none"),
not _check_soft_dependencies(["tensorflow"], severity="none"),
reason="skip test if required soft dependency not available",
)
def test_random_state_deep_learning_rgs():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def test_channel_selectors(trans):
if issubclass(trans, BaseChannelSelector):
# Need fit for channel selection
# Must select at least one channel
X, y = make_example_3d_numpy(n_cases=10, n_channels=6, n_timepoints=30)
X, _ = make_example_3d_numpy(n_cases=20, n_channels=6, n_timepoints=30)
y = np.array([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1])
cs = trans()
assert not cs.get_tag("fit_is_empty")
cs.fit(X, y)
Expand Down
1 change: 1 addition & 0 deletions aeon/utils/networks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Utils for tensorflow_addons."""
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ all_extras = [
"ruptures>=1.1.9",
"tbats>=1.1.0",
"tensorflow>=2.12; python_version < '3.12'",
"tensorflow-addons; python_version < '3.12'",
"torch>=1.13.1",
"tsfresh>=0.20.0",
"tslearn>=0.5.2",
Expand All @@ -93,10 +92,9 @@ all_extras = [
]
dl = [
"keras-self-attention",
"tensorflow>=2.12; python_version < '3.12'",
"tensorflow-addons; python_version < '3.12'",
# dependency of tensorflow, see issue #1724
"keras<3.4",
"tensorflow>=2.12; python_version < '3.12'",
]
unstable_extras = [
"mrsqm>=0.0.1,<0.1.0; platform_system == 'Darwin' and python_version < '3.12'", # requires gcc and fftw to be installed for Windows and some other OS (see http://www.fftw.org/index.html)
Expand Down

0 comments on commit 1e08b19

Please sign in to comment.