Spaces:
Runtime error
Runtime error
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
|