My main doubt if I can easly convert this script to run in a Jupyter notebook whithout have this error. The function tf.app.run() provide a wrapper that handles flag parsing. But looks like the tensorflow code forcefully exits the process in which it's running after main completes.
This is my main function:
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,
)
When I call in Jupyter notebook:
if __name__ == '__main__':
tf.app.run(main)
I had this error:
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