我主要怀疑我是否可以轻松将此脚本转换为在 Jupyter 笔记本中运行而不会出现此错误。函数 tf.app.run() 提供了一个处理标志解析的包装器。但看起来 tensorflow 代码在 main 完成后强制退出它正在运行的进程。
这是我的主要功能:
def main(_):
input_fn = make_input_fn
hparams = tf.contrib.training.HParams(
learning_rate=.1,
)
config = tf.ConfigProto(
# allow_soft_placement=True,
# log_device_placement=True
)
trainingConfig = tf.contrib.learn.RunConfig(
save_summary_steps=500,
save_checkpoints_steps=500,
model_dir=("/tmp/tf-logs/bucketized-01"),
session_config=config
)
estimator = tf.estimator.Estimator(
model_fn=make_model,
params=hparams,
config=trainingConfig
)
estimator.train(
input_fn=input_fn,
steps=TRAIN_EPOCHS,
)
当我在 Jupyter 笔记本中调用时:
if __name__ == '__main__':
tf.app.run(main)
我有这个错误:
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Restoring parameters from /tmp/tf-logs/bucketized-01/model.ckpt-2001
INFO:tensorflow:Saving checkpoints for 2002 into /tmp/tf-logs/bucketized-01/model.ckpt.
INFO:tensorflow:loss = 11.734686, step = 2002
INFO:tensorflow:global_step/sec: 4.84241
INFO:tensorflow:loss = 11.320501, step = 2102 (20.653 sec)
INFO:tensorflow:global_step/sec: 5.54159
INFO:tensorflow:loss = 9.874545, step = 2202 (18.044 sec)
INFO:tensorflow:global_step/sec: 5.20988
INFO:tensorflow:loss = 11.533301, step = 2302 (19.196 sec)
INFO:tensorflow:Saving checkpoints for 2401 into /tmp/tf-logs/bucketized-01/model.ckpt.
INFO:tensorflow:Loss for final step: 10.57784.
An exception has occurred, use %tb to see the full traceback.
SystemExit