* make regex compatible with new code

* fix #777 exceeds Locator.MAXTICKS
* set non-interactive backend when OS is not windows
* save figure as SVG
pull/1337/head
Adesun 7 years ago
parent 043289426b
commit 84f53a4b05
  1. 26
      scripts/log_parser/log_parser.py
  2. 2
      scripts/log_parser/readme.md
  3. 76285
      scripts/log_parser/test_new.log
  4. 2953
      scripts/log_parser/test_new.svg

@ -10,8 +10,13 @@ import os
import platform
import re
import sys
import matplotlib.pyplot as plt
# set non-interactive backend default when os is not windows
if sys.platform != 'win32':
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
@ -56,17 +61,19 @@ def log_parser(args):
iterations = []
losses = []
fig, ax = plt.subplots()
# set area we focus on
ax.set_ylim(0, 8)
major_locator = MultipleLocator(1)
major_locator = MultipleLocator()
minor_locator = MultipleLocator(0.5)
ax.yaxis.set_major_locator(major_locator)
ax.yaxis.set_minor_locator(minor_locator)
ax.yaxis.grid(True, which='minor')
pattern = re.compile(r"([\d]*): .*?, (.*?) avg,")
pattern = re.compile(r"([\d].*): .*?, (.*?) avg")
# print(pattern.findall(log_content))
matches = pattern.findall(log_content)
# print(type(matches[0]))
counter = 0
log_count = len(matches)
@ -92,14 +99,13 @@ def log_parser(args):
ax.plot(iterations, losses)
plt.xlabel('Iteration')
plt.ylabel('Loss')
plt.grid()
plt.tight_layout()
save_path = os.path.join(args.save_dir, file_name + '.png')
plt.savefig(save_path, dpi=300)
# saved as svg
save_path = os.path.join(args.save_dir, file_name + '.svg')
plt.savefig(save_path, dpi=300, format="svg")
if args.show_plot:
plt.show()
else:
plt.switch_backend('agg')
if __name__ == "__main__":

@ -7,7 +7,7 @@
2. --save-dir the directory to save loss curve, image and csv file
3. --log-file log file name to be parsed
4. --csv-file csv file name to save loss data, default it's same with training log file name
5. --show whether to show after finished parsing, default False
5. --show whether to show after finished parsing, default False, just works on windows or linux with GUI desktop
`python log_parser.py --source-dir ./ --save-dir ./ --log-file test.log --show true`

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 76 KiB

Loading…
Cancel
Save