IBM / CNN-Cert

Codes for reproducing the experimental results in "CNN-Cert: An Efficient Framework for Certifying Robustness of Convolutional Neural Networks", published at AAAI 2019
Apache License 2.0
27 stars 16 forks source link

Error while trying to reproduce the Setup #10

Closed lambdaxdotx closed 3 years ago

lambdaxdotx commented 3 years ago

Hi,

I'm trying to reproduce the Setup section. All works fine till the command:

python cnn_to_mlp.py

for which I get the error:

$ python cnn_to_mlp.py
Traceback (most recent call last):
  File "cnn_to_mlp.py", line 14, in <module>
    from tensorflow.contrib.keras.api.keras.models import Sequential
ModuleNotFoundError: No module named 'tensorflow.contrib'

Do you have any idea why?

AkhilanB commented 3 years ago

This may be because of a different Tensorflow version than what is supported by the code. This repository currently supports Tensorflow versions 1.10 and 1.12.

However, you may be able to adapt the code to support the version you are using. Specifically, in different Tensorflow versions, Keras may be referred to by tensorflow.keras instead of tensorflow.contrib.keras. Any pretrained models may also need to be retrained in the Tensorflow version you are using, or converted to the format used in the new version.

lambdaxdotx commented 3 years ago

Sorry for the late reply.

Indeed, after installing tensorflow 1.12 there was progress. But the process still ends with an error:

$ python cnn_to_mlp.py
[...]
Weights found
(784, 3380)
(3380, 2880)
(2880, 2420)
(2420, 10)
5000/5000 [==============================] - 2s 373us/step
Weights found
(784, 13520)
(13520, 11520)
(11520, 9680)
(9680, 10)
5000/5000 [==============================] - 19s 4ms/step
Weights found
(784, 3380)
(3380, 2880)
(2880, 2420)
(2420, 2000)
(2000, 10)
5000/5000 [==============================] - 2s 493us/step
Weights found
(3072, 4500)
(4500, 3920)
(3920, 3380)
(3380, 2880)
(2880, 2420)
(2420, 2000)
(2000, 10)
5000/5000 [==============================] - 6s 1ms/step
Weights found
(3072, 9000)
(9000, 7840)
(7840, 6760)
(6760, 5760)
(5760, 10)
5000/5000 [==============================] - 15s 3ms/step
Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x7f567e89c198>>
Traceback (most recent call last):
  File "session.py", line 738, in __del__
TypeError: 'NoneType' object is not callable

Any further idea? BTW, such an error seems not to bother the python pymain.py command that much (it seems to run...). Is it expected?

AkhilanB commented 3 years ago

I'm unable to reproduce this error. However, it looks like this error only occurs after all the model conversions are finished running, and is related to the Tensorflow session being closed via Keras. It may be ok to just ignore this error. If you want to resolve this error though, deleting the pycache folder might help.

Yes, python pymain.py should run correctly since all the models in cnn_to_mlp.py appear to be converted correctly despite the error.

lambdaxdotx commented 3 years ago

Thanks for your replies. Indeed, it seems to run fine.

BTW, the README section Setup says that table is set to 6, but AFAICT table is actually set to 13.

AkhilanB commented 3 years ago

Glad to hear it runs!

Thank you for pointing this out- I have updated the default table in the code.