CleverHans is incompatible with Tensorflow Addons - python

I have been trying to use CleverHans (https://github.com/tensorflow/cleverhans).
Background
I ran this file here - https://github.com/tensorflow/cleverhans/blob/master/cleverhans_tutorials/mnist_tutorial_tf.py, with Python 3.7.6 and TensorFlow 1.15.3, which led me to the following error:
ImportError: This version of TensorFlow Addons requires TensorFlow version >= 2; Detected an installation of version 1.15.3. Please upgrade TensorFlow to proceed.
However, CleverHans isn't really meant for TensorFlow's versions 2 and above, and they are working on publishing a new version. I actually even updated TensorFlow to 2.3.0 just to see what would happen. That led to a bunch of errors and error-fixing, and finally I got here:
/python3.7/site-packages/cleverhans/initializers.py", line 13, in __init__
super(HeReLuNormalInitializer, self).__init__(dtype=dtype)
TypeError: __init__() got an unexpected keyword argument 'dtype'
Clearly, CleverHans doesn't work with TensorFlow 2.
Question
My question is that how come the fgsm.py file (CleverHans) uses tensorflow_addons when tensorflow_addons doesn't work with TensorFlow <2. Also, I guess the only solution would be to make things work without tensorflow_addons, but I'm not sure how much effort would that be.
Any suggestions related to evading TensorFlow Addons or a completely new approach would be awesome.
Thanks!

Related

Is there a way to save a model using Tensorflow 2.6.0 so that it can be loaded back using Tensorflow 2.3.0?

I began writing my code with Tensorflow 2.6.0, but now I need to downgrade it to 2.3.0 since it needs to run on a GPU that doesn't support CUDA 11.
Some of the neural networks in my code are loaded from json files using the keras.models.model_from_json function, which apparently behaves differently in these two tf versions. While it works fine in 2.6.0, I get the following error in 2.3.0:
AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
Since it is loaded correctly with the more recent version of tf, I'm trying to save it in another format to hopefully be able to load it with tf 2.3.0. I tried both the keras SavedModel and HDF5 approach as well as the tf.saved_model.load approach:
When I try to load the models as SavedModels I get OSError: Unable to open file Permission denied, seems that keras is expecting a file rather than a folder;
Using either the HDF5 method or the tf.saved_model module ends with AttributeError: 'str' object has no attribute 'decode' when trying to load the models.
And I'm stuck here. The aforementioned methods work without any issues when I load the models back using Tensorflow 2.6.0, so I'm sure I saved them correctly.
Any help from someone more knowledgeable than me would be appreciated.

Migration of tensorflow python script to 2.1 version

I need to migrate some tensorflow scripts to 2.1 version. Reading about this task, I found that one of the main differences is related to tensorflow.contrib that has been removed and replaced as described in this document.
In my scripts, tensorflow.contrib is widely used. Also using indications in the document above, I cannot clearly understand where classes have been moved (e.g. tf.contrib.quantization)
Anyone can help me to understand how locate this library, and more in general libraries that are changed?
Tensorflow migratation guide would be the place where you can start
How to migrate your TensorFlow 1 code to TensorFlow 2

Best TensorFlow version & Object Detection API version for Object Detection in Windows

Hopefully this questions fits Stack Overflow question type.
So, I have been trying to get TensorFlow 2.0 & 2.1 version up and running for Object Detection, but found myself being constantly stuck with new deprecated/removed functions.
Tensorflow 2.* versions do not fit the model_train.py file which is used to finally train custom object detector, which in case uses old functions -_- from some 1.* versions. It might be a problem on my side, but I've tried both GPU and CPU versions and the original built in object detector did work for me (dogs, kites, and people) for 2.1 version, but no progress for creating custom object detectors due to various incompatibility issues.
Thus, I want to ask if anyone knows best Tensorflow version that would work with some version of Object Detection API from https://github.com/tensorflow/models as of February 2020. CPU/GPU difference does not matter, as I am able to
Thank you!
For trying out tensorflow 2 models use version 2.3.0 , it is compatible with newer models.If using tf 1.x models , use version 1.15.0.

module 'tensorflow_estimator.python.estimator.api._v2.estimator' has no attribute 'inputs'

I am using tensorflow version 2.0.0-beta1. While calling
tf.estimator.inputs.pandas_input_fn
it is giving me an error.
module 'tensorflow_estimator.python.estimator.api._v2.estimator' has no attribute 'inputs'
In order to identify the problem I tried with
tf.estimator.inputs
which gave me the following error
module 'tensorflow_estimator.python.estimator.api._v2.estimator' has no attribute 'inputs'
I have tried reinstalling tensorflow on my local machine and also on Google Colab but that doesn't seem to work. Is there any change in this function in newer version of tensorflow as compared to previous version of tensorflow i.e. (tf version 1.x)
In Tensorflow V1 While reading input from Pandas DataFrames for tf.estimator we used this command: tf.estimator.inputs.pandas_input_fn. But now due to API changes, we will have to replace that command with this one: tf.compat.v1.estimator.inputs.pandas_input_fn. Here we are getting the same command from the Version1 into Version2 of Tensorflow.
tf.compat.v1.estimator.inputs.pandas_input_fn
It's a great answer or explanation given for the problem by Tensor flow versions while working with TensorFlow use cases even I have faced the same issue with the inputs but after replacing the function with this as
input_fun=tf.compat.v1.estimator.inputs.pandas_input_fn(x=X_train,y=y_train,batch_size=100,num_epochs=None,shuffle=True)
the problem got resolved.
have a great day!
Thank you!
Happy Friendship Day to all IT professionals!
Regards,
Kalyani Reddy
Data Scientist

Error in prediction using sknn.mlp

I use Anaconda on a Windows 10 laptop with Python 2.7 and Spark 2.1. Built a deep learning model using Sknn.mlp package. I have completed the model. When I try to predict using the predict function, it throws an error. I run the same code on my Mac and it works just fine. Wondering what is wrong with my windows packages.
'NoneType' object is not callable
I verified input data. It is numpy.array and it does not have null value. Its dimension is same as training one and all attributed are the same. Not sure what it can be.
I don't work with Python on Windows, so this answer will be very vague, but maybe it will guide you in the right direction. Sometimes there are cross-platform errors due to one module still not being updated for the OS, frequently when another related module gets an update. I recall something happened to me with a django application which required somebody more familiar with Windows to fix it for me.
Maybe you could try with an environment using older versions of your modules until you find the culprit.
I finally solved the problem on windows. Here is the solution in case you face it.
The Theano package was faulty. I installed the latest version from github and then it threw another error as below:
RuntimeError: To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environment.
In order to solve this, I created a variable named MKL_Threading_Layer under user environment variable and passed GNU. Reset the kernel and it was working.
Hope it helps!

Categories