tensorflow / lucid

A collection of infrastructure and tools for research in neural network interpretability.
Apache License 2.0
4.65k stars 655 forks source link

Magic %tensorflow_version 1.x not supported in colab #306

Closed IcecreamArtist closed 1 year ago

IcecreamArtist commented 1 year ago

Tensorflow1 is currently not supported in colab, as stated in the error message. Unfortunately, lucid does not support tensorflow2 currently.

So is there still a way to use Lucid in colab?

Error message when running %tensorflow_version 1.x in colab:

ValueError                                Traceback (most recent call last)
[<ipython-input-16-8d2919c1d33c>](https://ygqcp6meja-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230203-060043-RC00_506856568#) in <module>
----> 1 get_ipython().run_line_magic('tensorflow_version', '1.x')

1 frames
[/usr/local/lib/python3.8/dist-packages/google/colab/_tensorflow_magics.py](https://ygqcp6meja-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20230203-060043-RC00_506856568#) in _tensorflow_version(line)
     33 
     34   if line.startswith("1"):
---> 35     raise ValueError(
     36         # pylint: disable=line-too-long
     37         textwrap.dedent("""\

ValueError: Tensorflow 1 is unsupported in Colab.

Your notebook should be updated to use Tensorflow 2.
See the guide at https://www.tensorflow.org/guide/migrate#migrate-from-tensorflow-1x-to-tensorflow-2.

I have tried using a way introduced in https://stackoverflow.com/questions/73215696/did-colab-suspend-tensorflow-1-x to downgrade the tensorflow in colab, but it raises an error that lucid is not installed correctly.

watermeleon commented 1 year ago

I had the same problem, and couldn't seem to make it work locally either. However, I found a solution to make it work locally using conda:

conda create -n "MyEnv" python=3.6 ipython
conda activate MyEnv
pip install tensorflow-gpu==1.15
pip install lucid
python -m ipykernel install --user --name="featViz"

Then open jupyter notebook and selecting the MyEnv as a kernel did the trick.

IcecreamArtist commented 1 year ago

Thank you for your reply.

Finally I found that there is no cudnn7 built in colab, which supports the tensorflow1.xx. Therefore, using Lucid in colab becomes impossible.

Thanks for your method, but I do not have enough computational power locally.

However, I found that Lucid can be used in Kaggle engine, and it works.