Skip to content

Instantly share code, notes, and snippets.

@BrianPugh
Created July 11, 2017 18:44
Show Gist options
  • Save BrianPugh/4571e5483c9c73456edfb7bc3ef1bc2e to your computer and use it in GitHub Desktop.
Save BrianPugh/4571e5483c9c73456edfb7bc3ef1bc2e to your computer and use it in GitHub Desktop.
meow!
def get_checkpoints(checkpoint_dir):
'''
Finds all checkpoints in a directory and returns them in order
from least iterations to most iterations
'''
meta_list=[]
for file in os.listdir(checkpoint_dir):
if file.endswith('.meta'):
meta_list.append(os.path.join(checkpoint_dir, file[:-5]))
meta_list = sort_nicely(meta_list)
return meta_list
def sort_nicely(l):
"""
Sort the given list in the way that humans expect.
From Ned Batchelder
https://nedbatchelder.com/blog/200712/human_sorting.html
"""
def alphanum_key(s):
""" Turn a string into a list of string and number chunks.
"z23a" -> ["z", 23, "a"]
"""
def tryint(s):
try:
return int(s)
except:
return s
return [ tryint(c) for c in re.split('([0-9]+)', s) ]
l.sort(key=alphanum_key)
return l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment