From e4eb775b6388c284ab307fa6a74f17aac93c0853 Mon Sep 17 00:00:00 2001 From: xra Date: Tue, 23 Aug 2022 00:03:32 +0900 Subject: [PATCH] added optional parameter to skip subprompt weight normalization allows more control when fine-tuning --- ldm/simplet2i.py | 12 ++++++++---- scripts/dream.py | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ldm/simplet2i.py b/ldm/simplet2i.py index 78b70000df..ab3195284a 100644 --- a/ldm/simplet2i.py +++ b/ldm/simplet2i.py @@ -142,7 +142,7 @@ The vast majority of these arguments default to reasonable values. def txt2img(self,prompt,outdir=None,batch_size=None,iterations=None, steps=None,seed=None,grid=None,individual=None,width=None,height=None, - cfg_scale=None,ddim_eta=None,strength=None,init_img=None): + cfg_scale=None,ddim_eta=None,strength=None,init_img=None,skip_normalize=False): """ Generate an image from the prompt, writing iteration images into the outdir The output is a list of lists in the format: [[filename1,seed1], [filename2,seed2],...] @@ -210,7 +210,9 @@ The vast majority of these arguments default to reasonable values. totalWeight = sum(weights) # normalize each "sub prompt" and add it for i in range(0,len(subprompts)): - weight = weights[i] / totalWeight + weight = weights[i] + if not skip_normalize: + weight = weight / totalWeight c = torch.add(c,model.get_learned_conditioning(subprompts[i]), alpha=weight) else: # just standard 1 prompt c = model.get_learned_conditioning(prompts) @@ -257,7 +259,7 @@ The vast majority of these arguments default to reasonable values. # There is lots of shared code between this and txt2img and should be refactored. def img2img(self,prompt,outdir=None,init_img=None,batch_size=None,iterations=None, steps=None,seed=None,grid=None,individual=None,width=None,height=None, - cfg_scale=None,ddim_eta=None,strength=None): + cfg_scale=None,ddim_eta=None,strength=None,skip_normalize=False): """ Generate an image from the prompt and the initial image, writing iteration images into the outdir The output is a list of lists in the format: [[filename1,seed1], [filename2,seed2],...] @@ -343,7 +345,9 @@ The vast majority of these arguments default to reasonable values. totalWeight = sum(weights) # normalize each "sub prompt" and add it for i in range(0,len(subprompts)): - weight = weights[i] / totalWeight + weight = weights[i] + if not skip_normalize: + weight = weight / totalWeight c = torch.add(c,model.get_learned_conditioning(subprompts[i]), alpha=weight) else: # just standard 1 prompt c = model.get_learned_conditioning(prompts) diff --git a/scripts/dream.py b/scripts/dream.py index 4e18492b3d..2625b6027f 100755 --- a/scripts/dream.py +++ b/scripts/dream.py @@ -233,6 +233,7 @@ def create_cmd_parser(): parser.add_argument('-i','--individual',action='store_true',help="generate individual files (default)") parser.add_argument('-I','--init_img',type=str,help="path to input image (supersedes width and height)") parser.add_argument('-f','--strength',default=0.75,type=float,help="strength for noising/unnoising. 0.0 preserves image exactly, 1.0 replaces it completely") + parser.add_argument('-x','--skip_normalize',action='store_true',help="skip subprompt weight normalization") return parser if readline_available: