【问题标题】:Mute logging in TPU estimatorTPU 估计器中的静音记录
【发布时间】:2019-04-23 17:53:02
【问题描述】:

我正在使用 BERT run_classifier 和 tensorflow TPUEstimator,每次我训练我的模型或使用估计器预测器进行预测时,我的屏幕上都会打印出太多的日志信息。我怎样才能摆脱这些信息。以下行被打印了一百万次:

INFO:tensorflow:Dequeue next (1) batch(es) of data from outfeed.
I0423 15:45:17.093261 140624241985408 tpu_estimator.py:540] Dequeue next (1) batch(es) of data from outfeed.

下面这行代码在我的屏幕上被写了一百万次(虽然没有问题,并且模型是使用 TPU 正确训练的)

E0423 15:44:54.258747 140624241985408 tpu.py:330] Operation of type Placeholder (module_apply_tokens/bert/encoder/layer_6/attention/output/dense/kernel) is not supported on the TPU. Execution will fail if this op is used in the graph. 
ERROR:tensorflow:Operation of type Placeholder (module_apply_tokens/bert/encoder/layer_6/attention/output/dense/bias) is not supported on the TPU. Execution will fail if this op is used in the graph. 

这是产生这种冗长的代码:

from bert import run_classifier
estimator = tf.contrib.tpu.TPUEstimator(
  use_tpu=True,
  model_fn=model_fn,
  config=get_run_config(OUTPUT_DIR),
  train_batch_size=TRAIN_BATCH_SIZE,
  eval_batch_size=EVAL_BATCH_SIZE,
  predict_batch_size=PREDICT_BATCH_SIZE,
)

input_features = run_classifier.convert_examples_to_features(prediction_examples, label_list, MAX_SEQ_LENGTH, tokenizer)
predict_input_fn = run_classifier.input_fn_builder(features=input_features, seq_length=MAX_SEQ_LENGTH, is_training=False, drop_remainder=True)
predictions = estimator.predict(predict_input_fn)

我怎样才能要求模型不要打印它们?

【问题讨论】:

    标签: tensorflow logging tensorflow-estimator verbosity tpu


    【解决方案1】:

    你应该可以set the logging verbosity level

    tf.logging.set_verbosity(v)
    

    在您的main() 方法的第一行,其中详细级别v 可能是:

    _level_names = {
      FATAL: 'FATAL',
      ERROR: 'ERROR',
      WARN: 'WARN',
      INFO: 'INFO',
      DEBUG: 'DEBUG',
    }
    

    v=tf.logging.FATAL 将打印最少数量的日志。

    【讨论】:

    • 谢谢!有效。但是没有办法获得信息但没有错误?我的意思是如果将日志详细程度设置为 INFO,输出中也会包含错误?
    • 这是设计使然。错误是比 INFO 更严重的情况。当较低级别的日志记录打开时,所有较高级别的日志记录也都打开。
    猜你喜欢
    • 1970-01-01
    • 2018-06-12
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 2012-11-08
    • 2012-07-05
    相关资源
    最近更新 更多