Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry Picking Drake53's Negative Prompt Support Commit #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ def main(args):
device=args.device
)
image = engine(
prompt=args.prompt,
init_image=None if args.init_image is None else cv2.imread(args.init_image),
mask=None if args.mask is None else cv2.imread(args.mask, 0),
strength=args.strength,
num_inference_steps=args.num_inference_steps,
guidance_scale=args.guidance_scale,
eta=args.eta
prompt = args.prompt,
init_image = None if args.init_image is None else cv2.imread(args.init_image),
mask = None if args.mask is None else cv2.imread(args.mask, 0),
strength = args.strength,
num_inference_steps = args.num_inference_steps,
guidance_scale = args.guidance_scale,
eta = args.eta,
unprompt = args.unprompt
)
cv2.imwrite(args.output, image)

Expand Down Expand Up @@ -79,5 +80,7 @@ def main(args):
parser.add_argument("--mask", type=str, default=None, help="mask of the region to inpaint on the initial image")
# output name
parser.add_argument("--output", type=str, default="output.png", help="output image name")
# unprompt
parser.add_argument("--unprompt", type=str, default="", help="negative prompt")
args = parser.parse_args()
main(args)
5 changes: 3 additions & 2 deletions stable_diffusion_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def __call__(
strength = 0.5,
num_inference_steps = 32,
guidance_scale = 7.5,
eta = 0.0
eta = 0.0,
unprompt = ""
):
# extract condition
tokens = self.tokenizer(
Expand All @@ -122,7 +123,7 @@ def __call__(
# do classifier free guidance
if guidance_scale > 1.0:
tokens_uncond = self.tokenizer(
"",
unprompt,
padding="max_length",
max_length=self.tokenizer.model_max_length,
truncation=True
Expand Down