48

I'm trying to run a tensorflow code in v2.0 and I'mg getting the following error

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

I don't want to simply remove it from the code.

  • why this code has been removed?
  • why should I do instead?

2 Answers 2

61

tf.logging was for Logging and Summary Operations and in TF 2.0 it has been removed in favor of the open-source absl-py, and to make the main tf.* namespace has functions that will be used more often.

In TF.2 lesser used functions are gone or moved into sub-packages like tf.math

So instead of tf.logging you could:

  • tf_upgrade_v2 will upgrade script and changes tf.logging to tf.compat.v1.logging
  • Python logging module can be used instead
  • Import absl-py library
Sign up to request clarification or add additional context in comments.

3 Comments

NOTE: This fix does not work for bert-as-a-service.
Syntax is as follows: tf_upgrade_v2 --infile foo.py --outfile bar.py , tf_upgrade_v2 --infile foo.ipynb --outfile bar.ipynb , tf_upgrade_v2 --intree ~/code/old --outtree ~/code/new , Note : replace foo.py with your filename
Any chance of an alternative as simple as tf.logging.info("...") ? tf.print() ?
8

If you are using someone else's code it's better to install same Tensorflow version as the author used, or downgrade your Tensorflow version. You may wanna try this:

pip install tensorflow==1.15.0

Or if you have gpu:

pip install tensorflow-gpu==1.15.0

You may still get depricated warnings, however you don't need to modify several files replacing tf with tf.compat.v1

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.