資源簡介
代碼的主體是Caffe提供的tools/extra文件中的python代碼,但是代碼無法在Windows下直接運行,此版本是我自己修改的。經過測試8中曲線都能正確畫出,如果你的積分有限,可以參考我們博客自行修改,或聯系我。謝謝你的支持

代碼片段和文件信息
#!/usr/bin/env?python
import?datetime
import?os
import?sys
def?extract_datetime_from_line(line?year):
????#?Expected?format:?I0210?13:39:22.381027?25210?solver.cpp:204]?Iteration?100?lr?=?0.00992565
????line?=?line.strip().split()
????month?=?int(line[0][1:3])
????day?=?int(line[0][3:])
????timestamp?=?line[1]
????pos?=?timestamp.rfind(‘.‘)
????ts?=?[int(x)?for?x?in?timestamp[:pos].split(‘:‘)]
????hour?=?ts[0]
????minute?=?ts[1]
????second?=?ts[2]
????microsecond?=?int(timestamp[pos?+?1:])
????dt?=?datetime.datetime(year?month?day?hour?minute?second?microsecond)
????return?dt
def?get_log_created_year(input_file):
????“““Get?year?from?log?file?system?timestamp
????“““
????log_created_time?=?os.path.getctime(input_file)
????log_created_year?=?datetime.datetime.fromtimestamp(log_created_time).year
????return?log_created_year
def?get_start_time(line_iterable?year):
????“““Find?start?time?from?group?of?lines
????“““
????start_datetime?=?None
????for?line?in?line_iterable:
????????line?=?line.strip()
????????if?line.find(‘Solving‘)?!=?-1:
????????????start_datetime?=?extract_datetime_from_line(line?year)
????????????break
????return?start_datetime
def?extract_seconds(input_file?output_file):
????with?open(input_file?‘r‘)?as?f:
????????lines?=?f.readlines()
????log_created_year?=?get_log_created_year(input_file)
????start_datetime?=?get_start_time(lines?log_created_year)
????assert?start_datetime?‘Start?time?not?found‘
????out?=?open(output_file?‘w‘)
????for?line?in?lines:
????????line?=?line.strip()
????????if?line.find(‘Iteration‘)?!=?-1:
????????????dt?=?extract_datetime_from_line(line?log_created_year)
????????????elapsed_seconds?=?(dt?-?start_datetime).total_seconds()
????????????out.write(‘%f\n‘?%?elapsed_seconds)
????out.close()
if?__name__?==?‘__main__‘:
????if?len(sys.argv)?3:
????????print(‘Usage:?./extract_seconds?input_file?output_file‘)
????????exit(1)
????extract_seconds(sys.argv[1]?sys.argv[2])
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-12-09?16:22??extra\
?????文件????????1966??2016-12-01?08:31??extra\extract_seconds.py
?????文件????????2413??2016-12-09?13:17??extra\extract_seconds.pyc
?????文件???????53602??2016-12-09?17:49??extra\INFO2016-12-09T12-54-26.log
?????文件????????1028??2016-12-09?16:52??extra\INFO2016-12-09T12-54-26.log.test
?????文件????????4079??2016-12-09?16:52??extra\INFO2016-12-09T12-54-26.log.train
?????文件????????1459??2016-12-01?08:31??extra\launch_resize_and_crop_images.sh
?????文件????????6853??2016-12-01?08:31??extra\parse_log.py
?????文件????????5367??2016-12-09?16:22??extra\parse_log.pyc
?????文件????????1859??2016-12-01?08:31??extra\parse_log.sh
?????文件????????2513??2016-12-01?08:31??extra\plot_log.gnuplot
?????文件????????7570??2016-12-09?17:48??extra\plot_training_log.py
?????文件????????4541??2016-12-01?08:31??extra\resize_and_crop_images.py
?????文件????????4880??2016-12-01?08:31??extra\summarize.py
?????文件???????34759??2016-12-09?16:52??extra\train.png
評論
共有 條評論