From 7c5e365f74cbe31f09029f531948f9073be62a12 Mon Sep 17 00:00:00 2001 From: Nate Baer Date: Sat, 12 Mar 2022 23:48:33 -0800 Subject: [PATCH 1/4] Check if using secondary model before loading it --- Disco_Diffusion.ipynb | 5 ++--- disco.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Disco_Diffusion.ipynb b/Disco_Diffusion.ipynb index 881e482..9a6ff1d 100644 --- a/Disco_Diffusion.ipynb +++ b/Disco_Diffusion.ipynb @@ -2321,15 +2321,14 @@ " 'use_scale_shift_norm': True,\n", " })\n", "\n", - "secondary_model_ver = 2\n", "model_default = model_config['image_size']\n", "\n", "\n", "\n", - "if secondary_model_ver == 2:\n", + "if use_secondary_model:\n", " secondary_model = SecondaryDiffusionImageNet2()\n", " secondary_model.load_state_dict(torch.load(f'{model_path}/secondary_model_imagenet_2.pth', map_location='cpu'))\n", - "secondary_model.eval().requires_grad_(False).to(device)\n", + " secondary_model.eval().requires_grad_(False).to(device)\n", "\n", "clip_models = []\n", "if ViTB32 is True: clip_models.append(clip.load('ViT-B/32', jit=False)[0].eval().requires_grad_(False).to(device)) \n", diff --git a/disco.py b/disco.py index e06ea5e..58ad5b5 100644 --- a/disco.py +++ b/disco.py @@ -2199,15 +2199,14 @@ elif diffusion_model == '256x256_diffusion_uncond': 'use_scale_shift_norm': True, }) -secondary_model_ver = 2 model_default = model_config['image_size'] -if secondary_model_ver == 2: +if use_secondary_model: secondary_model = SecondaryDiffusionImageNet2() secondary_model.load_state_dict(torch.load(f'{model_path}/secondary_model_imagenet_2.pth', map_location='cpu')) -secondary_model.eval().requires_grad_(False).to(device) + secondary_model.eval().requires_grad_(False).to(device) clip_models = [] if ViTB32 is True: clip_models.append(clip.load('ViT-B/32', jit=False)[0].eval().requires_grad_(False).to(device)) From 2a2755941044c2dab414aee16df135661e63db0e Mon Sep 17 00:00:00 2001 From: Adam Letts Date: Mon, 4 Apr 2022 13:56:54 -0400 Subject: [PATCH 2/4] Synchronize .ipynb with .py. Apply removal of timestep_respacing and diffusion_steps to .ipynb --- Disco_Diffusion.ipynb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Disco_Diffusion.ipynb b/Disco_Diffusion.ipynb index df48f19..84c6360 100644 --- a/Disco_Diffusion.ipynb +++ b/Disco_Diffusion.ipynb @@ -2240,8 +2240,7 @@ "use_secondary_model = True #@param {type: 'boolean'}\n", "diffusion_sampling_mode = 'ddim' #@param ['plms','ddim'] \n", "\n", - "timestep_respacing = '250' #@param ['25','50','100','150','250','500','1000','ddim25','ddim50', 'ddim75', 'ddim100','ddim150','ddim250','ddim500','ddim1000'] \n", - "diffusion_steps = 1000 #@param {type: 'number'}\n", + "\n", "use_checkpoint = True #@param {type: 'boolean'}\n", "ViTB32 = True #@param{type:\"boolean\"}\n", "ViTB16 = True #@param{type:\"boolean\"}\n", @@ -2333,9 +2332,9 @@ " model_config.update({\n", " 'attention_resolutions': '32, 16, 8',\n", " 'class_cond': False,\n", - " 'diffusion_steps': diffusion_steps,\n", + " 'diffusion_steps': 1000, #No need to edit this, it is taken care of later.\n", " 'rescale_timesteps': True,\n", - " 'timestep_respacing': timestep_respacing,\n", + " 'timestep_respacing': 250, #No need to edit this, it is taken care of later.\n", " 'image_size': 512,\n", " 'learn_sigma': True,\n", " 'noise_schedule': 'linear',\n", @@ -2351,9 +2350,9 @@ " model_config.update({\n", " 'attention_resolutions': '32, 16, 8',\n", " 'class_cond': False,\n", - " 'diffusion_steps': diffusion_steps,\n", + " 'diffusion_steps': 1000, #No need to edit this, it is taken care of later.\n", " 'rescale_timesteps': True,\n", - " 'timestep_respacing': timestep_respacing,\n", + " 'timestep_respacing': 250, #No need to edit this, it is taken care of later.\n", " 'image_size': 256,\n", " 'learn_sigma': True,\n", " 'noise_schedule': 'linear',\n", From 4d0bba9d6d82e6471731d1c51ac414bf8cef09df Mon Sep 17 00:00:00 2001 From: Chris Allen <48918354+zippy731@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:43:38 -0700 Subject: [PATCH 3/4] Don't run Turbo on frame 0 it needs precursors that are not there yet. --- Disco_Diffusion.ipynb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Disco_Diffusion.ipynb b/Disco_Diffusion.ipynb index c85ca42..3da90f1 100644 --- a/Disco_Diffusion.ipynb +++ b/Disco_Diffusion.ipynb @@ -1100,9 +1100,7 @@ " skip_steps = args.calc_frames_skip_steps\n", "\n", " if args.animation_mode == \"3D\":\n", - " if frame_num == 0:\n", - " pass\n", - " else:\n", + " if frame_num > 0:\n", " seed += 1 \n", " if resume_run and frame_num == start_frame:\n", " img_filepath = batchFolder+f\"/{batch_name}({batchNum})_{start_frame-1:04}.png\"\n", @@ -1413,7 +1411,7 @@ " image.save(f'{batchFolder}/{filename}')\n", " if args.animation_mode == \"3D\":\n", " # If turbo, save a blended image\n", - " if turbo_mode:\n", + " if turbo_mode and frame_num > 0:\n", " # Mix new image with prevFrameScaled\n", " blend_factor = (1)/int(turbo_steps)\n", " newFrame = cv2.imread('prevFrame.png') # This is already updated..\n", @@ -3274,4 +3272,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} From b54ec1e4681ef33b7b1a24b5966fb7b00da33d24 Mon Sep 17 00:00:00 2001 From: Chris Allen <48918354+zippy731@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:46:10 -0700 Subject: [PATCH 4/4] Don't run Turbo on frame 0 it needs precursors that are not there yet. --- disco.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/disco.py b/disco.py index 6345fa0..b34e403 100644 --- a/disco.py +++ b/disco.py @@ -1007,9 +1007,7 @@ def do_run(): skip_steps = args.calc_frames_skip_steps if args.animation_mode == "3D": - if frame_num == 0: - pass - else: + if frame_num > 0: seed += 1 if resume_run and frame_num == start_frame: img_filepath = batchFolder+f"/{batch_name}({batchNum})_{start_frame-1:04}.png" @@ -1320,7 +1318,7 @@ def do_run(): image.save(f'{batchFolder}/{filename}') if args.animation_mode == "3D": # If turbo, save a blended image - if turbo_mode: + if turbo_mode and frame_num > 0: # Mix new image with prevFrameScaled blend_factor = (1)/int(turbo_steps) newFrame = cv2.imread('prevFrame.png') # This is already updated..