Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'tensorflow.contrib' #182

Open
Lawrence-Krukrubo opened this issue Jun 25, 2023 · 26 comments
Open

ModuleNotFoundError: No module named 'tensorflow.contrib' #182

Lawrence-Krukrubo opened this issue Jun 25, 2023 · 26 comments

Comments

@Lawrence-Krukrubo
Copy link

I have tf==1.14 installed and python 3.7 I have been awake the whole night trying to sort this. Please please help.
My project is on AIX360 and I can't get it to work. Even after cloning the repo, the above error message keeps appearing whenever I load the CEMExplainer and others

@vijay-arya
Copy link
Collaborator

@Lawrence-Krukrubo pls try python 3.6 + tf1.14 for CEM.

@Lawrence-Krukrubo
Copy link
Author

I have now installed python=3.6.13 and tf=1.14
I use the pip install aix360 and get the following error:

Failed to build cvxopt ecos scs
ERROR: Could not build wheels for cvxopt, ecos, scs which use PEP 517 and cannot be installed directly

what should I do please?
do you think it will work if I cloned the AIX360 GitHub repo into this environment that has python=3.6.13 and tf=1.14?

@Lawrence-Krukrubo
Copy link
Author

Hi @vijay-arya I have read your paper "AI Explainability 360: Impact and Design" and the "AI Explainability 360 Toolkit". This toolkit is the focus of my Master's dissertation which I am working on, at the moment. My focus is on CEM and its unique use of PN and PP to justify and improve decisions made to customers. Please, I need this to work, so I can carry out a few experiments locally. Thanks

@vijay-arya
Copy link
Collaborator

@Lawrence-Krukrubo the following should work:

git clone https://github.com/Trusted-AI/AIX360
cd AIX360
pip install -e .[contrastive]

The installation instructions are also available here: https://github.com/Trusted-AI/AIX360/tree/master#installation
The latest version is not in pypi yet, so you will need to clone it from git as above and then install.

@Lawrence-Krukrubo
Copy link
Author

I have done every thing step by step and still getting the same error

ModuleNotFoundError: No module named 'tensorflow.contrib

the original installation guide on the page you sent has python=3.10 should I try that version of Python?

@Lawrence-Krukrubo
Copy link
Author

I tried to use python=3.10 in a new Conda env and got an incompatibility error for tf=1.14

@Lawrence-Krukrubo
Copy link
Author

3.10 won't work as Contrastive expects 3.6, which is what I already have in my env. I have python=3.6.13 and tf=1.14

@Lawrence-Krukrubo
Copy link
Author

Is there anything I can do please, is there a way to run the CEMExplainer from any other application like Watson Studio? Please, I am willing to pay for a subscription to get this to work. My entire dissertation hinges on this please

@Lawrence-Krukrubo
Copy link
Author

I just tried to run the nn.contrastive example and this runs fine. but the CEMExplainer keeps bringing up the module not found error.

@vijay-arya
Copy link
Collaborator

@Lawrence-Krukrubo I hope you are following these steps. Then you should be able to use CEMexplainer.

(base)$ conda create --name aix360 python=3.6
(base)$ conda activate aix360

(aix360)$ git clone https://github.com/Trusted-AI/AIX360
(aix360)$ cd AIX360
(aix360)$ pip install -e .[contrastive]

@Lawrence-Krukrubo
Copy link
Author

yes, I did so and it's just a bit frustrating. Let me delete the old env and start all over again, see if it would work.

@Lawrence-Krukrubo
Copy link
Author

I just followed your steps judiciously one after another. Exactly how you put it and I am despondent and sad to say the same issue persists...

ModuleNotFoundError: No module named 'tensorflow.contrib'

please isn't there something that can be done, a quick fix or stop-gap just to enable me run my local notebook?

@vijay-arya
Copy link
Collaborator

@Lawrence-Krukrubo when do you get this error. Which notebook you are trying to run and the code that gives you the error. Also some info on the system you are using (windows, mac, etc.)

@Lawrence-Krukrubo
Copy link
Author

Lawrence-Krukrubo commented Jun 26, 2023 via email

@vijay-arya
Copy link
Collaborator

vijay-arya commented Jun 26, 2023

@Lawrence-Krukrubo
If you are getting ModuleNotFoundError: No module named 'tensorflow.contrib error, then it means you have a higher version of tensorflow being used somewhere and you are running code that is compatible with TF1.x
https://stackoverflow.com/questions/55311534/how-to-fix-no-module-named-tensorflow-contrib-for-python-project

Since CEM is a white box explainer, the other place to check is if the ML model that you pass to it has been trained using TF 1.14 and not a higher version.

CEM is currently tested on windows, mac, & linux for python 3.6, TF1.14.

@Lawrence-Krukrubo
Copy link
Author

Lawrence-Krukrubo commented Jun 26, 2023 via email

@Lawrence-Krukrubo
Copy link
Author

Lawrence-Krukrubo commented Jun 26, 2023 via email

@vijay-arya
Copy link
Collaborator

nn.contrastive is a black box explainer, type of model does not matter.
CEM is a white box explainer, its code looks inside the model, so model's TF version would matter. Pls try using a model trained on TF1.14 if you'd like to use CEM.

@Lawrence-Krukrubo
Copy link
Author

Lawrence-Krukrubo commented Jun 26, 2023 via email

@vijay-arya
Copy link
Collaborator

The MNIST example is also run as a test for CEM from here: https://github.com/Trusted-AI/AIX360/blob/master/tests/contrastive/test_CEM.py

You can see the test run results here for windows, mac, and linux:
https://github.com/Trusted-AI/AIX360/actions/runs/5375947859/jobs/9752428343

@Lawrence-Krukrubo
Copy link
Author

Lawrence-Krukrubo commented Jun 26, 2023 via email

@Lawrence-Krukrubo
Copy link
Author

Hi @vijay-arya something really interesting happened. The Python test file ran successfully. when I tried using a Jupyter Notebook in my venv, I always got the module-not-found-error... But if I put the same code in any script or .py file within my venv, everything works fine!

The issue seems to be that jupyter notebook is somehow linked to a different version of tensorflow than the .py script files...

@Lawrence-Krukrubo
Copy link
Author

Any ideas how to fix this?

@Lawrence-Krukrubo
Copy link
Author

Hi @vijay-arya , I have been able to run CEM successfully in venv. The issue was my notebook. venv kept calling jupyter notebook from a different thread with tf > 1.14. So, by some strange feeling, I tried installing jupyter in venv, and voila! it all works well now

@Lawrence-Krukrubo
Copy link
Author

My code tho... I'm getting negative values as the difference between X_pn and X for PN scores. I'm under the impression that X_pn - X should return positive values, reflecting the gap found by the perturbation right?

@JKQuah
Copy link

JKQuah commented Oct 4, 2023

I could not install TensorFlow properly while installing contrastive. Please help.

:/src/AIX360# pip install -e .[contrastive]
Obtaining file:///src/AIX360
Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy in /usr/local/lib/python3.6/site-packages (from aix360==0.3.0) (1.19.5)
Requirement already satisfied: pandas in /usr/local/lib/python3.6/site-packages (from aix360==0.3.0) (1.1.5)
Requirement already satisfied: scikit-learn in /usr/local/lib/python3.6/site-packages (from aix360==0.3.0) (0.24.2)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/site-packages (from aix360==0.3.0) (3.3.4)
Collecting keras==2.3.1
Using cached Keras-2.3.1-py2.py3-none-any.whl (377 kB)
ERROR: Could not find a version that satisfies the requirement tensorflow==1.14 (from aix360[contrastive]) (from versions: none)
ERROR: No matching distribution found for tensorflow==1.14

:/src/AIX360# python --version
Python 3.6.15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants