Issue with tensorflow/Cleverhans
This error typically occurs when using an older version of TensorFlow with code that was written for a newer version. In this case, it looks like the code is trying to access the **GraphKeys** attribute of the **tensorflow** module, which was removed in **TensorFlow 2.0**.

To fix this error, you can try replacing **tf.GraphKey**s with **tf.compat.v1.GraphKeys** throughout your code. This should allow it to run with TensorFlow 2.0 and newer versions.

and there can be also other issue like It's possible that the CleverHans library is not installed on your system or it is not installed correctly. You can try reinstalling it using the following command:
```
!pip install cleverhans==3.1.0
``` Hello, thanks for replying. I saw a description like that on internet, I
tried it but it seems like it doesn't work on google colab. Maybe i need to
try more deeply again.
 Thanks anyway.

On Sat, Mar 25, 2023, 9:29 PM Durgesh Patel ***@***.***>
wrote:

> This error typically occurs when using an older version of TensorFlow with
> code that was written for a newer version. In this case, it looks like the
> code is trying to access the *GraphKeys* attribute of the *tensorflow*
> module, which was removed in *TensorFlow 2.0*.
>
> To fix this error, you can try replacing *tf.GraphKey*s with
> *tf.compat.v1.GraphKeys* throughout your code. This should allow it to
> run with TensorFlow 2.0 and newer versions.
>
> and there can be also other issue like It's possible that the CleverHans
> library is not installed on your system or it is not installed correctly.
> You can try reinstalling it using the following command:
>
> !pip install cleverhans==3.1.0
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/tensorflow/tensorflow/issues/60069#issuecomment-1483915384>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A5WEGCKITXYOQOMH3CK7UXDW55ISZANCNFSM6AAAAAAWEHG2AM>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
 @fabixs Deprecated apis are causing this issue in your implementation. Could you try to use the newer apis by replacing tf.GraphKeys with tf.compat.v1.GraphKeys in your code. Please install the Cleverhans again and rerun the kernel which will install the libraries. Thank you!  @sushreebarsa I appreciate your reply. But I don't have any line
tf.GraphKeys in my code, that's why I'm pretty confused. Looks, this is the
header of the code right here:
google colab points out an error from line 4 to line 9 .
1)import logging
2)import numpy as np
3)import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

4)from cleverhans.attacks import SaliencyMapMethod, FastGradientMethod
5)from cleverhans.utils_tf import model_train , model_eval, batch_eval,
 model_argmax
6)from cleverhans.attacks_tf import jacobian_graph
7)from cleverhans.utils import other_classes
8)from cleverhans.attacks import CarliniWagnerL2
9)from cleverhans.utils_keras import KerasModelWrapper


 This error is :

AttributeError: module 'tensorflow' has no attribute 'GraphKeys'

Not only I installed Cleverhans3.1.0 but I also installed tensorflow
2.11.0, keras 2.11.0, and all required packages
As I said before, I don't have any place in my code where I used
tf.GraphKey.
This error is gonna drive me crazy, I have already tried several methods
without getting a good solution.
Thanks in advance to anyone who can suggest me a better way to solve this
problem.









On Sat, Mar 25, 2023, 9:29 PM Durgesh Patel ***@***.***>
wrote:

> This error typically occurs when using an older version of TensorFlow with
> code that was written for a newer version. In this case, it looks like the
> code is trying to access the *GraphKeys* attribute of the *tensorflow*
> module, which was removed in *TensorFlow 2.0*.
>
> To fix this error, you can try replacing *tf.GraphKey*s with
> *tf.compat.v1.GraphKeys* throughout your code. This should allow it to
> run with TensorFlow 2.0 and newer versions.
>
> and there can be also other issue like It's possible that the CleverHans
> library is not installed on your system or it is not installed correctly.
> You can try reinstalling it using the following command:
>
> !pip install cleverhans==3.1.0
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/tensorflow/tensorflow/issues/60069#issuecomment-1483915384>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A5WEGCKITXYOQOMH3CK7UXDW55ISZANCNFSM6AAAAAAWEHG2AM>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
 @SuryanarayanaY I was able to replicate the issue on colab, please find the [gist](https://colab.research.google.com/gist/sushreebarsa/a23b461c0c330971a08016f929926905/60069.ipynb) here. 
Thank you! @fabixs ,

Is that third party library `cleverhans` using TF 1. versions ? I am sorry to say we are not supporting TF1.x versions currently. Also this is related to third party library `cleverhans` which we are not the right team to address. If you can share a code snippet(2.X version) that can reproduce this error without any third party libraries we will have a look. 

Thanks !
 This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60069">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60069">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

tf 2.11.*

### Custom Code

Yes

### OS Platform and Distribution

windows 10 64b

### Mobile device

Google colab

### Python version

3.9.16

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

NVIDIA T4 Tensor Core GPU

### Current Behaviour?

```shell
I try to run an adversarial machine learning program but I have an issue with Cleverhans library.
When I'm trying to import the following line :
from cleverhans.utils_tf import model_train , model_eval, batch_eval, model_argmax


 I'm using cleverhans 3.1.0 on google colab.
```


### Standalone code to reproduce the issue

```shell
AttributeError: module 'tensorflow' has no attribute 'GraphKeys'
```


### Relevant log output

```shell
import matplotlib . pyplot as plt

import tensorflow.compat.v1 as tf
from datetime import datetime,  timedelta
from sklearn.preprocessing import LabelEncoder , MinMaxScaler

from keras.models import Sequential
from keras.layers import Dense , Dropout
#from tensorflow.keras.optimizers import Adam 
from keras . optimizers import RMSprop, Adam

from tensorflow.python.platform import flags
from cleverhans.utils_tf import model_train , model_eval, batch_eval, model_argmax


AttributeError: module 'tensorflow' has no attribute 'GraphKeys'
```
</details>