在bash脚本中捕获Tensorflow输出

时间:2018-09-06 14:07:01

标签: python bash tensorflow

一个带有火车并评估火车规格的Tensorflow估计器的训练课程有时会被杀死。

我想在读取输出“ Killed”(由tf.logging.INFO生成)后恢复培训课程。理想情况下,一次又一次地执行python脚本。有没有一种简短的方法可以做到这一点?

2 个答案:

答案 0 :(得分:0)

没有太多经验,但是据我有限的知识,您可以转向在Linux中使用 pipe 。像这样

tail -f xxx.log | grep --line-buffered killed_information | while read msg ; do python train.py ; done

注意:Killed_information应该替换为train.py的实际错误输出

答案 1 :(得分:0)

while [ 1 ]; do

    if grep -Fxq "killed" logFile; then
       # code if found (Run your script again from here)
    fi

    #check every 5 minutes
    sleep 300

done

(代码来自https://stackoverflow.com/a/4749368/10008499

相关问题