adapt
adapt copied to clipboard
object has no attribute '_is_compiled'
When trying to run the DANN example from the API documentation with version 0.4.4 I encounter the error below. Version 0.4.3 does not produce this error, though.
from adapt.utils import make_classification_da
from adapt.feature_based import DANN
Xs, ys, Xt, yt = make_classification_da()
model = DANN(lambda_=0.1, Xt=Xt, metrics=["acc"], random_state=0)
model.fit(Xs, ys, epochs=100, verbose=0)
model.score(Xt, yt)
Traceback (most recent call last):
File "/mnt/home/kc2824/test-adapt/test.py", line 9, in <module>
model.fit(Xs, ys, epochs=100, verbose=0)
File "/.../python3.12/site-packages/adapt/base.py", line 1147, in fit
if (not self._is_compiled) or (self.pretrain_):
^^^^^^^^^^^^^^^^^
AttributeError: 'DANN' object has no attribute '_is_compiled'. Did you mean: '_jit_compile'?
Hi @kerrycobb, Sorry, but it seems that you are using python version 3.12. However, adapt is not currently working for this version. See python versions for adapt. You can create a new environment with python 3.11, until we update adapt for Python 3.12. Best,
I've encountered the error with 3.11 and 3.10 as well. So I'm using version 0.4.3 with python 3.10 for now. Just wanted to bring attention to this in case it was helpful.
Traceback (most recent call last):
File "/.../test.py", line 6, in <module>
model.fit(Xs, ys, epochs=100, verbose=0)
File "/.../python3.11/site-packages/adapt/base.py", line 1147, in fit
if (not self._is_compiled) or (self.pretrain_):
^^^^^^^^^^^^^^^^^
AttributeError: 'DANN' object has no attribute '_is_compiled'. Did you mean: '_jit_compile'?
Traceback (most recent call last):
File "/.../test.py", line 6, in <module>
model.fit(Xs, ys, epochs=100, verbose=0)
File "/.../python3.10/site-packages/adapt/base.py", line 1147, in fit
if (not self._is_compiled) or (self.pretrain_):
AttributeError: 'DANN' object has no attribute '_is_compiled'. Did you mean: '_jit_compile'?
Ok, thank you @kerrycobb, My guess is that the error comes from the last Tensorflow release. With Tensorflow 2.15, there should be no error, even with Adapt 0.4.4.
Adapt 0.4.3 forces Tensorflow version below 2.12, so it can explain why it works while Adapt 0.4.4 don't.
I tried the example on Google colab, and it works fine with Adapt 0.4.4. I think the default Tensorflow version of Colab is still 2.15.
Best,
Hi! Have a similar issue: I use Colab and simply install the latest version of ADAPT = 0.4.4. Then I run the example code for IWN: from sklearn.linear_model import RidgeClassifier from adapt.utils import make_classification_da from adapt.instance_based import IWN Xs, ys, Xt, yt = make_classification_da() model = IWN(RidgeClassifier(0.), Xt=Xt, sigma_init=0.1, random_state=0, pretrain=False, pretrain__epochs=100, pretrain__verbose=0) model.fit(Xs, ys, epochs=100, batch_size=256, verbose=1) model.score(Xt, yt)
And get
AttributeError: 'IWN' object has no attribute '_is_compiled'
forcing !pip install Tensorflow==2.15 made the trick =)
Hi @artem-math-1,
Thank you for reporting the issue!
Adapt is currently not working with tensorflow 2.16. Colab still uses tensorflow 2.15 by default, however, scikeras
, one dependency from adapt 0.4.4 requires tensorflow 2.16, pypi then updates tensorflow when installing adapt...
A solution to run your code in Colab is to first install adapt then reinstall tensorflow 2.15:
!pip install adapt
!pip install tensorflow==2.15
Then, you can run your code:
from sklearn.linear_model import RidgeClassifier
from adapt.utils import make_classification_da
from adapt.instance_based import IWN
Xs, ys, Xt, yt = make_classification_da()
model = IWN(RidgeClassifier(0.), Xt=Xt, sigma_init=0.1, random_state=0,
pretrain=False, pretrain__epochs=100, pretrain__verbose=0)
model.fit(Xs, ys, epochs=100, batch_size=256, verbose=1)
model.score(Xt, yt)