File size: 1,142 Bytes
d13869d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import re


def str2bool(str):
    return True if str.lower() == 'true' else False


def get_newest_ckpt(string_list):
    # ๅฎšไน‰ไธ€ไธชๆญฃๅˆ™่กจ่พพๅผๆจกๅผ๏ผŒ็”จไบŽๅŒน้…ๅญ—็ฌฆไธฒไธญ็š„ๆ•ฐๅญ—
    pattern = r'epoch=(\d+)-step=(\d+)\.ckpt'

    # ไฝฟ็”จๆญฃๅˆ™่กจ่พพๅผๆๅ–ๆฏไธชๅญ—็ฌฆไธฒไธญ็š„ๆ•ฐๅญ—ไฟกๆฏ๏ผŒๅนถๅˆ›ๅปบไธ€ไธชๅŒ…ๅซๅ…ƒ็ป„็š„ๅˆ—่กจ
    extracted_info = []
    for string in string_list:
        match = re.match(pattern, string)
        if match:
            epoch = int(match.group(1))
            step = int(match.group(2))
            extracted_info.append((epoch, step, string))
    # ๆŒ‰็…ง epoch ๅŽ้ข็š„ๆ•ฐๅญ—ๅ’Œ step ๅŽ้ข็š„ๆ•ฐๅญ—่ฟ›่กŒๆŽ’ๅบ
    sorted_info = sorted(
        extracted_info, key=lambda x: (x[0], x[1]), reverse=True)
    # ่Žทๅ–ๆœ€ๆ–ฐ็š„ ckpt ๆ–‡ไปถๅ
    newest_ckpt = sorted_info[0][2]
    return newest_ckpt


# ๆ–‡ๆœฌๅญ˜ๅœจไธ”ไธไธบ็ฉบๆ—ถ return True
def check_txt_file(file_path):
    try:
        with open(file_path, 'r') as file:
            text = file.readline().strip()
        assert text.strip() != ''
        return text
    except Exception:
        return False
    return False