我正在使用Google CoLab上的Tensorflow训练模型。 训练过程会在屏幕上输出很多行。
是否可以将所有python输出重定向到日志文件并稍后读取?
P.S。 我尝试了以下建议: https://colab.research.google.com/drive/1q2mhsj4bwwdQK-KZIxrIIKed8O11MQl0
但是它仅适用于系统命令(例如“ ls -la”等)。使用此代码,仍然可以将python命令写入标准输出。
!python /root/models/research/object_detection/model_main.py \
--pipeline_config_path=/drive/data/ssd_mobilenet_v1_0.75_depth_300x300_coco14_sync.config \
--model_dir=/drive/data/ \
--num_train_steps=50000 \
--num_eval_steps=2000 \
--alsologtostderr
答案 0 :(得分:0)
可以使用标准linux重定向和实用程序“ tee”将输出捕获到文件中
!python trainingScripty.py 2>&1 | tee TrainerLog.txt
以上命令应同时将输出消息和错误消息捕获到TrainerLog.txt
答案 1 :(得分:0)
Amit 的回答很好。附带说明:如果您收到类似于以下内容的错误消息:
tee: output.txt: Transport endpoint is not connected
并且您已经使用类似的东西在当前的 colab notebook 文件中安装了一个驱动器;
drive.mount('/content/gdrive', force_remount=True)
重新检查您是否没有尝试在您尝试运行的 Python 脚本中再次安装 gdrive 驱动器可能会有所帮助。