Created
July 11, 2017 18:44
-
-
Save BrianPugh/4571e5483c9c73456edfb7bc3ef1bc2e to your computer and use it in GitHub Desktop.
meow!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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