Did tensorflow at any point change 'tensorflow.sub' into 'tensorflow.subtract'? - tensorflow

I was testing some code I was given and got an error saying:
AttributeError: 'module' object has no attribute 'sub'
The module referred to is TensorFlow. To investigate this error I started looking into the TensorFlow source code and found a function 'tensorflow.subtract'. Replacing 'sub' by 'subtract' made the error go away.
However now I am still wondering why the error occurred in the first place. I can think of 2 reasons:
At some point TensorFlow renamed 'sub' to 'subtract' and the code I was given hasn't yet updated to accommodate that change. Changing 'sub' to 'subtract' simply updated the code to the newer version of TensorFlow
I have made some mistake in importing the wrong libraries and TensorFlow does actually have a 'sub' function. This would mean that changing to 'subtract' potentially altered the workings of the program.
Can anyone give advice on what the most likely scenario is here?

The TensorFlow 1.0 release contained multiple breaking changes to the API, including the renaming of tf.sub to tf.subtract (likewise, tf.mul was renamed to tf.multiply et cetera). Comprehensive lists of all changes can be found here:
https://www.tensorflow.org/install/migration
https://github.com/tensorflow/tensorflow/releases/tag/v1.0.0

Related

Best pratice on using `tf.compat.v1.metrics.auc`?

I try to migrate my code from tf1.* to tf2, while in tf2 doc it says that tf.compat.v1.metrics.auc is deprecated because "The value of AUC returned by this may race with the update". This statement is vague to me. Does it mean that it can't be used in multithreading context? If not, in what situation can I use this function?
tf.compat.v1.metrics.auc has been moved under tf.keras.
As mentioned in the error message itself you can start using tf.keras.metrics.AUC in Tf2.
There are some changes in hyper parameters in the updated version, details with the example can be found in the above mentioned document.

Unexpected keyword argument 'show_dtype'

I am trying to plot my model with the data types with the following the code:
plot_model(model, to_file='model/model.png', show_dtype=True, show_shapes=True, show_layer_names=True)
However, I get an error that show_dtype is not an acceptable parameter even though it appears on the TensorFlow documentation: https://www.tensorflow.org/api_docs/python/tf/keras/utils/plot_model
This is the first time that I have run into this issue. It seems that this may be due to having an earlier release if you downloaded it from Anaconda Forge rather than something else like Pip. It is a simple fix, however.
Basically, you need to go into the library source file and edit it to the current version that is shown on the TensorFlow documentation page.
The link to the GitHub page that you will copy the Python code from is here: https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/python/keras/utils/vis_utils.py#L278-L348
Afterwards, head to your library path and paste that Python code there.
For example, my path is the following: C:/ProgramData/Anaconda3/envs/ml/Lib/site-packages/tensorflow/python/keras/utils/vis_utils.py. Yours should be something similar.

How tf.contrib.seq2seq.TrainingHelper can be replaced in TensorFlow 2.2

I am trying to run the project from GitHub but I have a trouble with TrainingHelper. Now, I am stuck with it, I dont know how to convert it to tf2. The console always returns the error like this:
AttributeError: module 'tensorflow_addons.seq2seq' has no attribute 'TrainingHelper'
Please help me!
Seems to be https://www.tensorflow.org/addons/api_docs/python/tfa/seq2seq/TrainingSampler
The api is a bit different, though. Some parameters passed in the constructor in TrainingHelper, are passed in TrainingSampler.initialize() instead. Also there are minimal differences in some of the return values. So, you have to do some adaptation for code migration.

How to silence the UserWarning from scipy.ndimage.zoom

I'm using scipy.ndimage.zoom and I get this annoying warning:
UserWarning: From scipy 0.13.0, the output shape of zoom() is calculated with round() instead of int() - for these inputs the size of the returned array has changed.
I'm not sure what I should get from it, I started using it with SciPy 1.0.0 so I don't believe it really affects me.
I guess calling it UserWarning is a bit questionable given it's not intended for user consumption, but maybe the intended user is the developer importing the library.
I'm using multiprocessing and I get one warning per process, even more annoying.
Is there a sane way to silent it?
It was easier than I thought, leaving the question for future reference in case anyone needs this.
import warnings
warnings.filterwarnings('ignore', '.*output shape of zoom.*')
Your proposed solution did not work for me. But what does work is:
import warnings
# other nice code
with warnings.catch_warnings():
warnings.simplefilter("ignore")
x = scipy.ndimage.interpolation.zoom(...)

compiling inception_client.cc without bazel

I need a simple function for my c++ program to be able to pull predictions from the tensorflow model server so I decided to user the inception client as a starting point.
I've followed the advice from here:
https://github.com/tensorflow/tensorflow/issues/2412
I'm currently getting various compile errors such as:
"undefined reference to tensorflow::serving::PredictRequest::_slow_mutable_model_spec()" and "undefined reference to tensorflow::serving::PredictRequest::~PredictRequest()"
Am I missing a library or something.
Is there a simpler way to make the function without the need for tensorflow in c++?