Skip to content

Commit 68bb557

Browse files
Merge pull request #119 from antoinedemathelin/master
fix: Fix compatibility issue with latest Tensorflow version
2 parents 077349e + 053f81c commit 68bb557

File tree

11 files changed

+44
-24
lines changed

11 files changed

+44
-24
lines changed

.github/workflows/run-test-coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v2
19-
- name: Set up Python 3.8
19+
- name: Set up Python 3.11
2020
uses: actions/setup-python@v2
2121
with:
22-
python-version: '3.8'
22+
python-version: '3.11'
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip

.github/workflows/run-test.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@ jobs:
1313
build:
1414
strategy:
1515
matrix:
16-
python-version: [3.6, 3.7, 3.8, 3.9]
16+
python-version: ['3.8', '3.9', '3.10', '3.11']
1717
os: [ubuntu-latest, windows-latest, macos-latest]
18-
exclude:
19-
- os: windows-latest
20-
python-version: 3.9
21-
- os: ubuntu-latest
22-
python-version: 3.6
2318
runs-on: ${{ matrix.os }}
2419
steps:
2520
- uses: actions/checkout@v2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ docs_build/
2121
docs/html/
2222
docs/doctrees/
2323
adapt/datasets.py
24-
datasets/
24+
datasets/
25+
debug.ipynb

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ADAPT
22

33
[![PyPI version](https://badge.fury.io/py/adapt.svg)](https://pypi.org/project/adapt)
4-
[![Build Status](https://github.com/adapt-python/adapt/workflows/build/badge.svg)](https://github.com/adapt-python/adapt/actions)
4+
[![Build Status](https://github.com/adapt-python/adapt/actions/workflows/run-test.yml/badge.svg)](https://github.com/adapt-python/adapt/actions)
55
[![Python Version](https://img.shields.io/badge/python-3.6%20|%203.7%20|%203.8|%203.9-blue)](https://img.shields.io/badge/python-3.6%20|%203.7%20|%203.8|%203.9-blue)
66
[![Codecov Status](https://codecov.io/gh/adapt-python/adapt/branch/master/graph/badge.svg?token=IWQXMYGY2Q)](https://codecov.io/gh/adapt-python/adapt)
77

@@ -72,11 +72,12 @@ The following dependencies are required and will be installed with the library:
7272
- `tensorflow` (>= 2.0)
7373
- `scikit-learn`
7474
- `cvxopt`
75+
- `scikeras`
7576

7677
If for some reason, these packages failed to install, you can do it manually with:
7778

7879
```
79-
pip install numpy scipy tensorflow scikit-learn cvxopt
80+
pip install numpy scipy tensorflow scikit-learn cvxopt scikeras
8081
```
8182

8283
Finally import the module in your python scripts with:
@@ -87,6 +88,15 @@ import adapt
8788

8889
A simple example of usage is given in the [Quick-Start](#Quick-Start) below.
8990

91+
### Stable environments [Updated Dec 2023]
92+
93+
ADAPT sometimes encounters incompatibility issue after a new Tensorflow release. In this case, you can use the following environment, which has passed all tests. ADAPT should work well on it:
94+
- OS: `ubuntu-22.04, windows-2022, macos-12`
95+
- Python versions: `3.8 to 3.11`
96+
97+
```
98+
pip install numpy==1.26.2 scipy==1.11.4 tensorflow==2.15.0 scikit-learn==1.3.2 cvxopt==1.3.2 scikeras==0.12.0
99+
```
90100

91101
## ADAPT Guideline
92102

adapt/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
from sklearn.metrics.pairwise import KERNEL_PARAMS
1414
from sklearn.exceptions import NotFittedError
1515
from tensorflow.keras import Model
16-
from tensorflow.keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor
16+
try:
17+
from tensorflow.keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor
18+
except:
19+
from scikeras.wrappers import KerasClassifier, KerasRegressor
1720
try:
1821
from tensorflow.keras.optimizers.legacy import RMSprop
1922
except:
@@ -1623,7 +1626,7 @@ def _get_length_dataset(self, dataset, domain="src"):
16231626

16241627

16251628
def _check_for_batch(self, dataset):
1626-
if dataset.__class__.__name__ == "BatchDataset":
1629+
if "BatchDataset" in dataset.__class__.__name__:
16271630
return True
16281631
if hasattr(dataset, "_input_dataset"):
16291632
return self._check_for_batch(dataset._input_dataset)

adapt/instance_based/_iwc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def fit_weights(self, Xs, Xt, warm_start=False, **kwargs):
170170
else:
171171
y_pred = self.classifier_.predict(Xs).ravel()
172172

173-
self.weights_ = 1. / (y_pred + EPS) - 1.
173+
self.weights_ = 1. / np.clip(y_pred, EPS, 1.) - 1.
174174

175175
return self.weights_
176176

adapt/instance_based/_tradaboost.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def fit(self, X, y, Xt=None, yt=None,
218218
self : returns an instance of self
219219
"""
220220
set_random_seed(self.random_state)
221-
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
221+
# tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
222222

223223
Xs, ys = check_arrays(X, y, accept_sparse=True)
224224
Xt, yt = self._get_target_data(Xt, yt)
@@ -757,9 +757,9 @@ class TwoStageTrAdaBoostR2(TrAdaBoostR2):
757757
--------
758758
>>> from sklearn.linear_model import Ridge
759759
>>> from adapt.utils import make_regression_da
760-
>>> from adapt.instance_based import TrAdaBoostR2
760+
>>> from adapt.instance_based import TwoStageTrAdaBoostR2
761761
>>> Xs, ys, Xt, yt = make_regression_da()
762-
>>> model = TrAdaBoostR2(Ridge(), n_estimators=10, Xt=Xt[:10], yt=yt[:10], random_state=0)
762+
>>> model = TwoStageTrAdaBoostR2(Ridge(), n_estimators=10, Xt=Xt[:10], yt=yt[:10], random_state=0)
763763
>>> model.fit(Xs, ys)
764764
Iteration 0 - Cross-validation score: 0.2956 (0.0905)
765765
Iteration 1 - Cross-validation score: 0.2956 (0.0905)
@@ -814,7 +814,7 @@ def fit(self, X, y, Xt=None, yt=None,
814814
sample_weight_tgt=None,
815815
**fit_params):
816816
set_random_seed(self.random_state)
817-
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
817+
# tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
818818

819819
Xs, ys = check_arrays(X, y, accept_sparse=True)
820820
Xt, yt = self._get_target_data(Xt, yt)

adapt/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
from sklearn.utils import check_array
1212
from sklearn.linear_model import LinearRegression, LogisticRegression
1313
from sklearn.base import BaseEstimator, ClassifierMixin, RegressorMixin, clone
14-
from tensorflow.keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor
14+
try:
15+
from tensorflow.keras.wrappers.scikit_learn import KerasClassifier, KerasRegressor
16+
except:
17+
from scikeras.wrappers import KerasClassifier, KerasRegressor
1518
import tensorflow as tf
1619
import tensorflow.keras.backend as K
1720
from tensorflow.keras import Sequential, Model

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
numpy
22
scipy
3-
tensorflow < 2.12
3+
tensorflow
44
scikit-learn
5-
cvxopt <= 1.3.0
5+
cvxopt
6+
scikeras

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
author_email='[email protected]',
1414
license='BSD-2',
1515
packages=find_packages(exclude=["tests"]),
16-
install_requires=["numpy>=1.16", "scipy>=1.0", "tensorflow<2.12", "scikit-learn>=0.2", "cvxopt<=1.3.0"],
16+
install_requires=["numpy", "scipy", "tensorflow", "scikit-learn", "cvxopt", "scikeras"],
1717
zip_safe=False,
1818
long_description=long_description,
1919
long_description_content_type='text/markdown'

0 commit comments

Comments
 (0)