mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
* make regex compatible with new code
* fix #777 exceeds Locator.MAXTICKS * set non-interactive backend when OS is not windows * save figure as SVG
This commit is contained in:
@ -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`
|
||||
|
||||
|
76285
scripts/log_parser/test_new.log
Normal file
76285
scripts/log_parser/test_new.log
Normal file
File diff suppressed because it is too large
Load Diff
2953
scripts/log_parser/test_new.svg
Normal file
2953
scripts/log_parser/test_new.svg
Normal file
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 76 KiB |
Reference in New Issue
Block a user