读取训练进度日志文件,但其中写入了二进制文件 [英] Reading a training progress log file, but binaries are written in it
问题描述
我正在运行一个程序,它将进度条输出到文件train.2.log
.这是指向文件 train.2.log 的链接,该文件看起来像就像终端上的以下内容一样:
这是第1行
Training ...
这是第2行
epoch iteration main/loss main/loss_ctc main/loss_att ...
这是第3行
0 100 455.209 899.082 264.978 ...
当您调用head -n3 train.2.log
时没有任何问题,它很好地显示了前三行,但是在文本文件中它不是人类可读的,因为其中写入了二进制文件<0x1b>
(请参见 train.2.log ).
问题:如何修改文件以使其易于阅读?
问题似乎是您同时输出了培训进度和&它记录到相同的输出流.如果通过将Python输出重定向到终端(app.py > train.log
)中的文件而得到train.2.log
,但仍然希望观察它的进度,那么建议您将日志打印到单独的流中,例如stderr
. /p>
您可以使用print("Log message", file=sys.stderr)
在Python中实现此目标,然后重定向程序输出:
app.py 2>train.log
这样app.py
将照常将进度条打印到stdout
,而培训日志可在stderr
上使用,而没有混合进度指示.
I was running a program, and it will output the progress bar to a file train.2.log
. Here's a link to the file train.2.log, which looks like the following on terminal :
This is line 1
Training ...
This is line 2
epoch iteration main/loss main/loss_ctc main/loss_att ...
This is line 3
0 100 455.209 899.082 264.978 ...
There are no problems when u were to call head -n3 train.2.log
, it shows the first 3 lines very well, but in the text file its not human-readable, because of the binaries <0x1b>
that are written within it (see train.2.log).
Question : How do i modify the file such that it becomes human readable ?
Usually progress bars are written such that \r
is used instead of \n
, following this question.
Hence i tried this solution, which did not work as the program that i called doesn't seem to be using \r
.
The problem seems to be that you output both training progress & it's log to the same output stream. If you got the train.2.log
by redirecting the Python output to a file in terminal (app.py > train.log
), but still want to observe it's progress, then I'd suggest printing the log to a separate stream, like stderr
.
You can achieve that in Python with print("Log message", file=sys.stderr)
, then redirect program output:
app.py 2>train.log
This way app.py
will print the progress bar to stdout
as usual, while the training log is available on stderr
without progress indication mixed in.
这篇关于读取训练进度日志文件,但其中写入了二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!