AttributeError: module 'tensorflow' has no attribute 'logging'. Did you mean: '_logging'?
时间: 2023-09-13 11:07:34 浏览: 223
This error occurs when you are trying to use a logging function in TensorFlow but the attribute is not found. The cause of this error is that in TensorFlow 2.0, the logging module was removed and replaced with the Python logging module.
To fix this error, replace any instance of `import tensorflow.logging as logging` with `import logging` and update the logging statements accordingly.
For example, change `logging.info("message")` to `logging.getLogger().info("message")`
Here is an example code snippet with the updated logging import:
```python
import logging
import tensorflow as tf
# Set logging level
logging.getLogger().setLevel(logging.INFO)
# Perform TensorFlow operations
a = tf.constant(1)
b = tf.constant(2)
c = tf.add(a, b)
# Log result
logging.getLogger().info("Result: {}".format(c))
```
阅读全文