marcoancona / DeepExplain

A unified framework of perturbation and gradient-based attribution methods for Deep Neural Networks interpretability. DeepExplain also includes support for Shapley Values sampling. (ICLR 2018)
https://arxiv.org/abs/1711.06104
MIT License
720 stars 133 forks source link

compatibility problem with tensorflow 2 #50

Closed fallahmad closed 4 years ago

fallahmad commented 4 years ago

Hello! thank you for this amazing package you created. We are currently encountering some problems of compatibility with tensorflow 2. Once we install the package, we cannot even import the library because:

`

AttributeError Traceback (most recent call last)

in ----> 1 from deepexplain.tensorflow import DeepExplain /home/eprifti/src/deepexplain/deepexplain/tensorflow/__init__.py in ----> 1 from .methods import DeepExplain /home/eprifti/src/deepexplain/deepexplain/tensorflow/methods.py in 552 553 --> 554 class DeepExplain(object): 555 556 def __init__(self, graph=None, session=tf.get_default_session()): /home/eprifti/src/deepexplain/deepexplain/tensorflow/methods.py in DeepExplain() 554 class DeepExplain(object): 555 --> 556 def __init__(self, graph=None, session=tf.get_default_session()): 557 self.method = None 558 self.batch_size = None AttributeError: module 'tensorflow' has no attribute 'get_default_session'` we tried to fix it without any success. Do you have any suggestion?
cuckoong commented 4 years ago

I have the same problem. Have you fixed it?

marcoancona commented 4 years ago

Sorry I had no time to look into this yet. TF2 brings major changes and since DeepExplain uses some low level features the porting might not be straight-forward. Does it work if you disable tf2 features?

Definitely, DeepExplain does not support Eager Execution which can be disabled with

import tensorflow as tf
tf.compat.v1.disable_eager_execution()

You can also try disabling v2 features entirely:

import tensorflow as tf
tf.compat.v1.disable_v2_behavior()
yiyousong commented 4 years ago

I encounter the same problem but due to different reason. For me when I tried to import tensorflow 2 and DeepExplain

import numpy as np import pandas as pd import tensorflow as tf from deepexplain.tensorflow import DeepExplain and here is the error, seems like it is due to tensorflow_core was imported twice

KeyError: "Registering two gradient with name 'DeepExplainGrad'! (Previous registration was in register C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\framework\registry.py:66)"

I've tried tf.compat.v1.disable_eager_execution() tf.compat.v1.disable_v2_behavior() import tensorflow.compat.v1 as tf none worked

sorry, I don't know why my code are flattened

fallahmad commented 4 years ago

Hi @John-Tsemin disabling Tensorflow 2 behavior with tf.compat.v1.disable_eager_execution() tf.compat.v1.disable_v2_behavior() did not solve my problem, what i did to solve was to create another virtualenv with Tensorflow 1.15.0, indeed this version of Tensorflow has most of the functions of Tensorflow 2 and legacy Tensorflow 1, so I got DeepExplain working perfectly without changing a bit of my code. Hope that helps ;)

cap76 commented 2 years ago

Just to check, was there any update on this? There still seems to be incompatibility with tf version 2 even if eager_execution or v2 behavior was disabled.

Zhangyang823 commented 2 years ago

你好,来信已收到~~