问题
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
.
回答1:
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.
来源:https://stackoverflow.com/questions/60981316/reading-a-training-progress-log-file-but-binaries-are-written-in-it