简体   繁体   中英

AttributeError: module 'tensorflow.compat.v2' has no attribute 'logging'

I have updated to the latest tensorflow via pip3 :

pip3 install tensorflow

The following code is generating the error in the question title

tf.logging.info('embedding_name: %s', FLAGS.embedding_dimension)

AttributeError: module 'tensorflow.compat.v2' has no attribute 'logging'

Is this an out-of-date way to invoke the logging? Is there an alternative?

tf.logging.info('embedding_name: %s', FLAGS.embedding_dimension) is indeed an out-dated way of doing this. It is no longer supported. You can use tf.get_logger as an alternative. Here is an working example.

import tensorflow as tf
import logging

logger = tf.get_logger()
logger.setLevel(logging.INFO)

logger.info(' Hello World from TF')

outputs:

INFO:tensorflow: Hello World from TF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM