File size: 1,873 Bytes
0b32ad6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# -*- coding: utf-8 -*- #
"""*********************************************************************************************"""
# FileName [ utility/get_best_dev.py ]
# Synopsis [ script that finds the best dev score from log ]
# Author [ Andy T. Liu (github.com/andi611) ]
# Copyright [ Copyleft(c), Speech Lab, NTU, Taiwan ]
"""*********************************************************************************************"""
"""
Usage:
`python utility/get_best_dev.py result/downstream/example/log.log`
`python utility/get_best_dev.py result/downstream/example/log.log $stop_step`
where $stop_step is an int that specifies the maximum log step to search for.
"""
###############
# IMPORTATION #
###############
import os
import sys
import glob
########
# MAIN #
########
def main():
log_file = str(sys.argv[1])
ckpts = glob.glob(os.path.dirname(log_file) + '/states-*.ckpt')
sorted_ckpts = sorted(ckpts, key=lambda ckpt: int(ckpt.split('.')[0].split('-')[-1]))
print(f'The last ckpt: {sorted_ckpts[-1]}')
if len(sys.argv) == 3:
stop_step = int(sys.argv[2])
else:
stop_step = 99999999
best_dev, best_step, best_test = None, None, None
with open(log_file) as f:
lines = f.readlines()
for line in lines:
line = line.strip('\n').split(' ')
if line[0].lower() == 'new':
best_dev = line[-1]
best_step = line[-2].strip(':')
if line[0].lower() == 'test':
if line[-2].strip(':') == best_step:
best_test = line[-1]
if int(line[-2].strip(':')) > stop_step:
break
print(f'The best dev score {best_dev} at step {best_step}, accoupanied by this test score {best_test}')
if __name__ == '__main__':
main()
|