disco-diffusion
disco-diffusion copied to clipboard
Resume from latest if there is no latest
I have enabled resume_run and set resume_from_frame to latest. I would expect that if there is no "latest" image in the directory yet, it would start normally from scratch. But it will start from -1.
Then in the output directory there are MyBatchName(-1)_0000.png files instead of the correct MyBatchName(0)_0000.png.
PS: I can fix it and send a pull request, just let me know if it makes sense.
I've got some changes in progress so I won't merge it right now.. but I think the following awkward, untested code may work:
if resume_run:
if run_to_resume == 'latest':
try:
batchNum
except:
batchNum = len(glob(f"{batchFolder}/{batch_name}(*)_settings.txt"))-1
if batchNum < 0:
print("resume_run set to True, but there is no run to resume. Starting a new run.")
resume_run = False
else:
batchNum = int(run_to_resume)
if resume_run:
if resume_from_frame == 'latest':
start_frame = len(glob(batchFolder+f"/{batch_name}({batchNum})_*.png"))
if animation_mode == '3D' and turbo_mode and start_frame > turbo_preroll and start_frame % int(turbo_steps) != 0:
start_frame = start_frame - (start_frame % int(turbo_steps))
else:
start_frame = int(resume_from_frame)+1
if animation_mode == '3D' and turbo_mode and start_frame > turbo_preroll and start_frame % int(turbo_steps) != 0:
start_frame = start_frame - (start_frame % int(turbo_steps))
if retain_overwritten_frames is True:
existing_frames = len(glob(batchFolder+f"/{batch_name}({batchNum})_*.png"))
frames_to_save = existing_frames - start_frame
print(f'Moving {frames_to_save} frames to the Retained folder')
move_files(start_frame, existing_frames, batchFolder, retainFolder)
else:
start_frame = 0
batchNum = len(glob(batchFolder+"/*.txt"))
while os.path.isfile(f"{batchFolder}/{batch_name}({batchNum})_settings.txt") or os.path.isfile(f"{batchFolder}/{batch_name}-{batchNum}_settings.txt"):
batchNum += 1