我是Tensorflow的新手,使用official tutorial tf.estimator.DNNClassifier和自定义估计器来构建简单的NN来解决分类问题。
培训期间:
dnn_model = tf.estimator.DNNClassifier(hidden_units=[10,10,10],
feature_columns = my_features_column,
n_classes=5,
optimizer = tf.train.AdamOptimizer()
)
dnn_model.train(input_fn=train_input_func)
它将在特定时间报告损失,如下所示:
INFO:tensorflow:Calling model_fn.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Restoring parameters from /tmp/tmphwkvj5le/model.ckpt-150
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Saving checkpoints for 150 into /tmp/tmphwkvj5le/model.ckpt.
INFO:tensorflow:loss = 133.04277, step = 150
INFO:tensorflow:global_step/sec: 115.114
INFO:tensorflow:loss = 128.15938, step = 250 (0.872 sec)
INFO:tensorflow:global_step/sec: 134.317
INFO:tensorflow:loss = 123.093094, step = 350 (0.743 sec)
INFO:tensorflow:global_step/sec: 133.573
INFO:tensorflow:loss = 117.80729, step = 450 (0.748 sec)
INFO:tensorflow:global_step/sec: 135.081
INFO:tensorflow:loss = 114.07168, step = 550 (0.741 sec)
INFO:tensorflow:Saving checkpoints for 650 into /tmp/tmphwkvj5le/model.ckpt.
INFO:tensorflow:Loss for final step: 118.19583.
我想每批或每个时期打印分类准确度,就像keras中的日志信息一样:
Epoch 1/20
5000/5000 [==============================] - 1s 157us/step - loss: 1.4885 - acc: 0.3276 - val_loss: 1.4397 - val_acc: 0.3620
Epoch 2/20
5000/5000 [==============================] - 0s 66us/step - loss: 1.3792 - acc: 0.3922 - val_loss: 1.4001 - val_acc: 0.3768
.
.
如何找到有关此问题的教程?我发现所有讨论的都是更低级的API(张量,会话等)。
答案 0 :(得分:1)
您要在估算器列中使用“挂钩”选项。
您要使用的特定钩子是这个:https://www.tensorflow.org/api_docs/python/tf/train/LoggingTensorHook
这里解决了类似的问题: https://stackoverflow.com/a/45716062/10498246 他们在不同的训练功能上使用了测井张量钩。