module 'tensorflow' has no attribute 'logging'

Hadi Rasekh picture Hadi Rasekh · Mar 23, 2019 · Viewed 31.6k times · Source

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?

Answer

Hadi Rasekh picture Hadi Rasekh · Mar 23, 2019

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