AttributeError: module 'tensorflow' has no attribute 'get_default_session'
See original GitHub issueInstalled dice-ml from pypi.
import dice_ml
from dice_ml.utils import helpers # helper functions
d = dice_ml.Data(dataframe=helpers.load_adult_income_dataset(),
continuous_features=['age', 'hours_per_week'],
outcome_name='income')
m = dice_ml.Model(model_path=dice_ml.utils.helpers.get_adult_income_modelpath())
exp = dice_ml.Dice(d,m)
Getting the following error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-d3dad7eed1c9> in <module>
8 m = dice_ml.Model(model_path=dice_ml.utils.helpers.get_adult_income_modelpath())
9 # DiCE explanation instance
---> 10 exp = dice_ml.Dice(d,m)
~/anaconda3/envs/diceml/lib/python3.6/site-packages/dice_ml/dice.py in __init__(self, data_interface, model_interface, **kwargs)
15 """
16
---> 17 self.decide_implementation_type(data_interface, model_interface, **kwargs)
18
19 def decide_implementation_type(self, data_interface, model_interface, **kwargs):
~/anaconda3/envs/diceml/lib/python3.6/site-packages/dice_ml/dice.py in decide_implementation_type(self, data_interface, model_interface, **kwargs)
21
22 self.__class__ = decide(data_interface, model_interface)
---> 23 self.__init__(data_interface, model_interface, **kwargs)
24
25 # To add new implementations of DiCE, add the class in explainer_interfaces subpackage and import-and-return the class in an elif loop as shown in the below method.
~/anaconda3/envs/diceml/lib/python3.6/site-packages/dice_ml/explainer_interfaces/dice_tensorflow1.py in __init__(self, data_interface, model_interface)
26
27 # create TensorFLow session if one is not already created
---> 28 if tf.get_default_session() is not None:
29 self.dice_sess = tf.get_default_session()
30 else:
AttributeError: module 'tensorflow' has no attribute 'get_default_session'
My pip freeze result
absl-py==0.11.0
appnope==0.1.0
argon2-cffi==20.1.0
astunparse==1.6.3
async-generator==1.10
attrs==20.2.0
backcall==0.2.0
bleach==3.2.1
cachetools==4.1.1
certifi==2020.6.20
cffi==1.14.3
chardet==3.0.4
dataclasses==0.7
decorator==4.4.2
defusedxml==0.6.0
dice-ml==0.4
entrypoints==0.3
future==0.18.2
gast==0.3.3
google-auth==1.22.1
google-auth-oauthlib==0.4.2
google-pasta==0.2.0
grpcio==1.33.2
h5py==2.10.0
idna==2.10
importlib-metadata==2.0.0
ipykernel==5.3.4
ipython==7.16.1
ipython-genutils==0.2.0
ipywidgets==7.5.1
jedi==0.17.2
Jinja2==2.11.2
joblib==0.17.0
jsonschema==3.2.0
jupyter==1.0.0
jupyter-client==6.1.7
jupyter-console==6.2.0
jupyter-core==4.6.3
jupyterlab-pygments==0.1.2
Keras-Preprocessing==1.1.2
lazy-import==0.2.2
Markdown==3.3.3
MarkupSafe==1.1.1
mistune==0.8.4
mkl-fft==1.2.0
mkl-random==1.1.1
mkl-service==2.3.0
nbclient==0.5.1
nbconvert==6.0.7
nbformat==5.0.8
nest-asyncio==1.4.2
notebook==6.1.4
numpy @ file:///opt/concourse/worker/volumes/live/e6a5a904-ea21-4841-4eec-d53e1ac1014c/volume/numpy_and_numpy_base_1603479626870/work
oauthlib==3.1.0
olefile==0.46
opt-einsum==3.3.0
packaging==20.4
pandas==0.25.3
pandocfilters==1.4.3
parso==0.7.1
pexpect==4.8.0
pickleshare==0.7.5
Pillow @ file:///opt/concourse/worker/volumes/live/06069510-e277-4aed-54f4-6dfdcb84a461/volume/pillow_1603822272490/work
prometheus-client==0.8.0
prompt-toolkit==3.0.3
protobuf==3.13.0
ptyprocess==0.6.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
Pygments==2.7.2
pyparsing==2.4.7
pyrsistent==0.17.3
python-dateutil==2.8.1
pytz==2020.1
pyzmq==19.0.2
qtconsole==4.7.7
QtPy==1.9.0
requests==2.24.0
requests-oauthlib==1.3.0
rsa==4.6
scikit-learn==0.23.2
scipy==1.5.3
Send2Trash==1.5.0
six==1.15.0
tensorboard==2.3.0
tensorboard-plugin-wit==1.7.0
tensorflow==2.3.1
tensorflow-cpu==2.3.1
tensorflow-estimator==2.3.0
tensorflow-gpu==1.1.0
termcolor==1.1.0
terminado==0.9.1
testpath==0.4.4
threadpoolctl==2.1.0
torch==1.7.0
torchaudio==0.7.0a0+ac17b64
torchvision==0.8.1
tornado==6.0.4
traitlets==4.3.3
typing-extensions @ file:///tmp/build/80754af9/typing_extensions_1598376058250/work
urllib3==1.25.11
wcwidth==0.2.5
webencodings==0.5.1
Werkzeug==1.0.1
widgetsnbextension==3.5.1
wrapt==1.12.1
zipp==3.4.0
If I change torch or tensorflow version other issues crop up. .
If fresh dice-ml install done in a new env where dice only install torch and tensorflow, then the error is
AttributeError: module 'torch.jit' has no attribute '_script_if_tracing'
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
AttributeError: module 'tensorflow' has no attribute 'Session'
According to TF 1:1 Symbols Map , in TF 2.0 you should use tf.compat.v1.Session() instead of tf.Session().
Read more >AttributeError: module 'tensorflow' has no attribute 'Session'
New to tensorflow, I am facing this error help me with this!
Read more >module 'tensorflow' has no attribute 'Session' [SOLVED]
In this article, we have demonstrated how to fix the error "AttributeError: module 'tensorflow' has no attribute 'Session'" while running a TensorFlow code....
Read more >Attribute Error: TensorFlow has no attribute session - YouTube
In this Python TensorFlow video tutorial, I have shared the solution for Python TensorFlow Error: TensorFlow has no attribute session.
Read more >How to fix AttributeError: module 'tensorflow' has no attribute ...
in this video you will learn how to fix tensorflow session error in python this video is very useful if you are beginner...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
DiCE internally selects a version of the explainer implementation based on the
backend
parameter todice_ml.Model
. The default version is TensorFlow 1.x so you need to set it manually if you are using TF2 or PyTorch. Please check out the section Loading the ML model in this notebook: https://github.com/interpretml/DiCE/blob/master/docs/source/notebooks/DiCE_getting_started.ipynb.Specifically, for your question, doing the below will resolve the error:
backend = 'TF'+tf.__version__[0] # TF2 in your case
ML_modelpath = helpers.get_adult_income_modelpath(backend=backend)
m = dice_ml.Model(model_path= ML_modelpath, backend=backend)
Same issue here for the README example and also a new environment with installed everything from the requirements files!
To reproduce error:
And finally I chosed mynewenvironment for the notebook kernel.
For the first cell in jupyter notebook (the example from README.md)
Running this code would gives me error
AttributeError: module 'tensorflow' has no attribute 'get_default_session'
.My System: