def __resume_from_dir__(self, dir):
# setup working directory
working_dir = os.path.realpath(dir)
self.timestamp = os.path.basename(working_dir)
# Set up result folder structure
results_path = "{}/results".format(working_dir, self.timestamp)
# Set up tensorboard directory
tensorboard = "{}/tensorboard".format(working_dir, self.timestamp)
# set path to kill file (if this file exists abort run)
kill_file_name = "ABORT_RUN"
kill_file = os.path.join(working_dir, kill_file_name)
if os.path.exists(kill_file):
os.remove(kill_file)
# create plot file to plot by default
plot_file_name = "PLOT_ON"
plot_file = os.path.join(working_dir, plot_file_name)
if not (os.path.exists(results_path) or not os.path.exists(tensorboard)):
raise Exception("can not resume from given directory")
checkpoints = glob.glob1(results_path, "*.ckpt*")
checkpoints = [checkpoint for checkpoint in checkpoints if
not (".meta" in checkpoint or ".index" in checkpoint)]
checkpoints = natsorted(checkpoints)
checkpoint = os.path.join(results_path, checkpoints[-1])
if not os.path.exists(checkpoint):
raise Exception("could not find checkpoint in given directory")
if not checkpoint.endswith("ckpt"):
checkpoint = checkpoint[:checkpoint.index(".ckpt.") + 5]
return [working_dir, results_path, tensorboard, kill_file, plot_file, checkpoint]
评论列表
文章目录