From 1704be96f8345f0191ca0801ddd539f5643d6dc2 Mon Sep 17 00:00:00 2001 From: Adam Letts Date: Wed, 30 Mar 2022 14:29:54 -0400 Subject: [PATCH] Slight turbo mode cleanup. Added questionable code to protect people who may modify the settings code (or that may hurt them - It could go either way) --- Disco_Diffusion.ipynb | 53 ++++++++++++++++++++++--------------------- disco.py | 53 ++++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/Disco_Diffusion.ipynb b/Disco_Diffusion.ipynb index 3d55ced..aeb6be6 100644 --- a/Disco_Diffusion.ipynb +++ b/Disco_Diffusion.ipynb @@ -1119,30 +1119,31 @@ "\n", " ### Turbo mode - skip some diffusions, use 3d morph for clarity and to save time\n", " turbo_blend = False # default for non-turbo frame saving\n", - " if turbo_mode == True and frame_num == turbo_preroll: #start tracking oldframe\n", - " next_step_pil.save('oldFrameScaled.png')#stash for later blending \n", - " if turbo_mode == True and frame_num > turbo_preroll:\n", - " #set up 2 warped image sequences, old & new, to blend toward new diff image\n", - " old_frame = do_3d_step('oldFrameScaled.png', frame_num, midas_model, midas_transform)\n", - " old_frame.save('oldFrameScaled.png')\n", - " if frame_num % int(turbo_steps) != 0: \n", - " print('turbo skip this frame: skipping clip diffusion steps')\n", - " filename = f'{args.batch_name}({args.batchNum})_{frame_num:04}.png'\n", - " blend_factor = ((frame_num % int(turbo_steps))+1)/int(turbo_steps)\n", - " print('turbo skip this frame: skipping clip diffusion steps and saving blended frame')\n", - " newWarpedImg = cv2.imread('prevFrameScaled.png')#this is already updated..\n", - " oldWarpedImg = cv2.imread('oldFrameScaled.png')\n", - " blendedImage = cv2.addWeighted(newWarpedImg, blend_factor, oldWarpedImg,1-blend_factor, 0.0)\n", - " cv2.imwrite(f'{batchFolder}/{filename}',blendedImage)\n", - " next_step_pil.save(f'{img_filepath}') # save it also as prev_frame to feed next iteration\n", - " turbo_blend = False\n", - " continue\n", - " else:\n", - " #if not a skip frame, will run diffusion and need to blend.\n", - " oldWarpedImg = cv2.imread('prevFrameScaled.png')\n", - " cv2.imwrite(f'oldFrameScaled.png',oldWarpedImg)#swap in for blending later \n", - " turbo_blend = True # flag to blend frames after diff generated...\n", - " print('clip/diff this frame - generate clip diff image')\n", + " if turbo_mode:\n", + " if frame_num == turbo_preroll: #start tracking oldframe\n", + " next_step_pil.save('oldFrameScaled.png')#stash for later blending \n", + " elif frame_num > turbo_preroll:\n", + " #set up 2 warped image sequences, old & new, to blend toward new diff image\n", + " old_frame = do_3d_step('oldFrameScaled.png', frame_num, midas_model, midas_transform)\n", + " old_frame.save('oldFrameScaled.png')\n", + " if frame_num % int(turbo_steps) != 0: \n", + " print('turbo skip this frame: skipping clip diffusion steps')\n", + " filename = f'{args.batch_name}({args.batchNum})_{frame_num:04}.png'\n", + " blend_factor = ((frame_num % int(turbo_steps))+1)/int(turbo_steps)\n", + " print('turbo skip this frame: skipping clip diffusion steps and saving blended frame')\n", + " newWarpedImg = cv2.imread('prevFrameScaled.png')#this is already updated..\n", + " oldWarpedImg = cv2.imread('oldFrameScaled.png')\n", + " blendedImage = cv2.addWeighted(newWarpedImg, blend_factor, oldWarpedImg,1-blend_factor, 0.0)\n", + " cv2.imwrite(f'{batchFolder}/{filename}',blendedImage)\n", + " next_step_pil.save(f'{img_filepath}') # save it also as prev_frame to feed next iteration\n", + " turbo_blend = False\n", + " continue\n", + " else:\n", + " #if not a skip frame, will run diffusion and need to blend.\n", + " oldWarpedImg = cv2.imread('prevFrameScaled.png')\n", + " cv2.imwrite(f'oldFrameScaled.png',oldWarpedImg)#swap in for blending later \n", + " turbo_blend = True # flag to blend frames after diff generated...\n", + " print('clip/diff this frame - generate clip diff image')\n", "\n", " init_image = 'prevFrameScaled.png'\n", " init_scale = args.frames_scale\n", @@ -3006,11 +3007,11 @@ " batchNum = int(run_to_resume)\n", " if resume_from_frame == 'latest':\n", " start_frame = len(glob(batchFolder+f\"/{batch_name}({batchNum})_*.png\"))\n", - " if turbo_mode == True and start_frame > turbo_preroll and start_frame % int(turbo_steps) != 0:\n", + " if animation_mode != '3D' and turbo_mode == True and start_frame > turbo_preroll and start_frame % int(turbo_steps) != 0:\n", " start_frame = start_frame - (start_frame % int(turbo_steps))\n", " else:\n", " start_frame = int(resume_from_frame)+1\n", - " if turbo_mode == True and start_frame > turbo_preroll and start_frame % int(turbo_steps) != 0:\n", + " if animation_mode != '3D' and turbo_mode == True and start_frame > turbo_preroll and start_frame % int(turbo_steps) != 0:\n", " start_frame = start_frame - (start_frame % int(turbo_steps))\n", " if retain_overwritten_frames is True:\n", " existing_frames = len(glob(batchFolder+f\"/{batch_name}({batchNum})_*.png\"))\n", diff --git a/disco.py b/disco.py index ff055d6..5f67d1f 100644 --- a/disco.py +++ b/disco.py @@ -1026,30 +1026,31 @@ def do_run(): ### Turbo mode - skip some diffusions, use 3d morph for clarity and to save time turbo_blend = False # default for non-turbo frame saving - if turbo_mode == True and frame_num == turbo_preroll: #start tracking oldframe - next_step_pil.save('oldFrameScaled.png')#stash for later blending - if turbo_mode == True and frame_num > turbo_preroll: - #set up 2 warped image sequences, old & new, to blend toward new diff image - old_frame = do_3d_step('oldFrameScaled.png', frame_num, midas_model, midas_transform) - old_frame.save('oldFrameScaled.png') - if frame_num % int(turbo_steps) != 0: - print('turbo skip this frame: skipping clip diffusion steps') - filename = f'{args.batch_name}({args.batchNum})_{frame_num:04}.png' - blend_factor = ((frame_num % int(turbo_steps))+1)/int(turbo_steps) - print('turbo skip this frame: skipping clip diffusion steps and saving blended frame') - newWarpedImg = cv2.imread('prevFrameScaled.png')#this is already updated.. - oldWarpedImg = cv2.imread('oldFrameScaled.png') - blendedImage = cv2.addWeighted(newWarpedImg, blend_factor, oldWarpedImg,1-blend_factor, 0.0) - cv2.imwrite(f'{batchFolder}/{filename}',blendedImage) - next_step_pil.save(f'{img_filepath}') # save it also as prev_frame to feed next iteration - turbo_blend = False - continue - else: - #if not a skip frame, will run diffusion and need to blend. - oldWarpedImg = cv2.imread('prevFrameScaled.png') - cv2.imwrite(f'oldFrameScaled.png',oldWarpedImg)#swap in for blending later - turbo_blend = True # flag to blend frames after diff generated... - print('clip/diff this frame - generate clip diff image') + if turbo_mode: + if frame_num == turbo_preroll: #start tracking oldframe + next_step_pil.save('oldFrameScaled.png')#stash for later blending + elif frame_num > turbo_preroll: + #set up 2 warped image sequences, old & new, to blend toward new diff image + old_frame = do_3d_step('oldFrameScaled.png', frame_num, midas_model, midas_transform) + old_frame.save('oldFrameScaled.png') + if frame_num % int(turbo_steps) != 0: + print('turbo skip this frame: skipping clip diffusion steps') + filename = f'{args.batch_name}({args.batchNum})_{frame_num:04}.png' + blend_factor = ((frame_num % int(turbo_steps))+1)/int(turbo_steps) + print('turbo skip this frame: skipping clip diffusion steps and saving blended frame') + newWarpedImg = cv2.imread('prevFrameScaled.png')#this is already updated.. + oldWarpedImg = cv2.imread('oldFrameScaled.png') + blendedImage = cv2.addWeighted(newWarpedImg, blend_factor, oldWarpedImg,1-blend_factor, 0.0) + cv2.imwrite(f'{batchFolder}/{filename}',blendedImage) + next_step_pil.save(f'{img_filepath}') # save it also as prev_frame to feed next iteration + turbo_blend = False + continue + else: + #if not a skip frame, will run diffusion and need to blend. + oldWarpedImg = cv2.imread('prevFrameScaled.png') + cv2.imwrite(f'oldFrameScaled.png',oldWarpedImg)#swap in for blending later + turbo_blend = True # flag to blend frames after diff generated... + print('clip/diff this frame - generate clip diff image') init_image = 'prevFrameScaled.png' init_scale = args.frames_scale @@ -2829,11 +2830,11 @@ if resume_run: batchNum = int(run_to_resume) if resume_from_frame == 'latest': start_frame = len(glob(batchFolder+f"/{batch_name}({batchNum})_*.png")) - if turbo_mode == True and start_frame > turbo_preroll and start_frame % int(turbo_steps) != 0: + if animation_mode != '3D' and turbo_mode == True 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 turbo_mode == True and start_frame > turbo_preroll and start_frame % int(turbo_steps) != 0: + if animation_mode != '3D' and turbo_mode == True 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"))