feature: negative prompting
- feature: negative prompting. `--negative-prompt` or `ImaginePrompt(..., negative_prompt="ugly, deformed, extra arms, etc")` - feature: a default negative prompt is added to all generations. Images in SD-2.0 don't look bad anymore. Images in 1.5 look improved as well.
@ -230,6 +230,10 @@ docker run -it --gpus all -v $HOME/.cache/huggingface:/root/.cache/huggingface -
|
|||||||
[Example Colab](https://colab.research.google.com/drive/1rOvQNs0Cmn_yU1bKWjCOHzGVDgZkaTtO?usp=sharing)
|
[Example Colab](https://colab.research.google.com/drive/1rOvQNs0Cmn_yU1bKWjCOHzGVDgZkaTtO?usp=sharing)
|
||||||
|
|
||||||
## ChangeLog
|
## ChangeLog
|
||||||
|
**7.0.0**
|
||||||
|
- feature: negative prompting. `--negative-prompt` or `ImaginePrompt(..., negative_prompt="ugly, deformed, extra arms, etc")`
|
||||||
|
- feature: a default negative prompt is added to all generations. Images in SD-2.0 don't look bad anymore. Images in 1.5 look improved as well.
|
||||||
|
|
||||||
**6.1.2**
|
**6.1.2**
|
||||||
- fix: add back in memory-efficient algorithms
|
- fix: add back in memory-efficient algorithms
|
||||||
|
|
||||||
|
@ -147,20 +147,16 @@ def imagine(
|
|||||||
seed_everything(prompt.seed)
|
seed_everything(prompt.seed)
|
||||||
model.tile_mode(prompt.tile_mode)
|
model.tile_mode(prompt.tile_mode)
|
||||||
with lc.timing("conditioning"):
|
with lc.timing("conditioning"):
|
||||||
neutral_conditioning = None
|
# need to expand if doing batches
|
||||||
if prompt.prompt_strength != 1.0:
|
neutral_conditioning = _prompts_to_embeddings(
|
||||||
neutral_conditioning = model.get_learned_conditioning(
|
prompt.negative_prompt, model
|
||||||
batch_size * [""]
|
)
|
||||||
)
|
log_conditioning(neutral_conditioning, "neutral conditioning")
|
||||||
log_conditioning(neutral_conditioning, "neutral conditioning")
|
|
||||||
if prompt.conditioning is not None:
|
if prompt.conditioning is not None:
|
||||||
positive_conditioning = prompt.conditioning
|
positive_conditioning = prompt.conditioning
|
||||||
else:
|
else:
|
||||||
total_weight = sum(wp.weight for wp in prompt.prompts)
|
positive_conditioning = _prompts_to_embeddings(
|
||||||
positive_conditioning = sum(
|
prompt.prompts, model
|
||||||
model.get_learned_conditioning(wp.text)
|
|
||||||
* (wp.weight / total_weight)
|
|
||||||
for wp in prompt.prompts
|
|
||||||
)
|
)
|
||||||
log_conditioning(positive_conditioning, "positive conditioning")
|
log_conditioning(positive_conditioning, "positive conditioning")
|
||||||
|
|
||||||
@ -405,5 +401,14 @@ def imagine(
|
|||||||
yield result
|
yield result
|
||||||
|
|
||||||
|
|
||||||
|
def _prompts_to_embeddings(prompts, model):
|
||||||
|
total_weight = sum(wp.weight for wp in prompts)
|
||||||
|
conditioning = sum(
|
||||||
|
model.get_learned_conditioning(wp.text) * (wp.weight / total_weight)
|
||||||
|
for wp in prompts
|
||||||
|
)
|
||||||
|
return conditioning
|
||||||
|
|
||||||
|
|
||||||
def prompt_normalized(prompt):
|
def prompt_normalized(prompt):
|
||||||
return re.sub(r"[^a-zA-Z0-9.,\[\]-]+", "_", prompt)[:130]
|
return re.sub(r"[^a-zA-Z0-9.,\[\]-]+", "_", prompt)[:130]
|
||||||
|
@ -16,6 +16,12 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.argument("prompt_texts", nargs=-1)
|
@click.argument("prompt_texts", nargs=-1)
|
||||||
|
@click.option(
|
||||||
|
"--negative-prompt",
|
||||||
|
default=config.DEFAULT_NEGATIVE_PROMPT,
|
||||||
|
show_default=True,
|
||||||
|
help="Negative prompt. Things to try and exclude from images. Same negative prompt will be used for all images.",
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--prompt-strength",
|
"--prompt-strength",
|
||||||
default=7.5,
|
default=7.5,
|
||||||
@ -177,6 +183,7 @@ logger = logging.getLogger(__name__)
|
|||||||
def imagine_cmd(
|
def imagine_cmd(
|
||||||
ctx,
|
ctx,
|
||||||
prompt_texts,
|
prompt_texts,
|
||||||
|
negative_prompt,
|
||||||
prompt_strength,
|
prompt_strength,
|
||||||
init_image,
|
init_image,
|
||||||
init_image_strength,
|
init_image_strength,
|
||||||
@ -235,6 +242,7 @@ def imagine_cmd(
|
|||||||
prompt_iterator = prompt_expanding_iterators[prompt_text]
|
prompt_iterator = prompt_expanding_iterators[prompt_text]
|
||||||
prompt = ImaginePrompt(
|
prompt = ImaginePrompt(
|
||||||
next(prompt_iterator),
|
next(prompt_iterator),
|
||||||
|
negative_prompt=negative_prompt,
|
||||||
prompt_strength=prompt_strength,
|
prompt_strength=prompt_strength,
|
||||||
init_image=init_image,
|
init_image=init_image,
|
||||||
init_image_strength=init_image_strength,
|
init_image_strength=init_image_strength,
|
||||||
|
@ -3,6 +3,15 @@ from dataclasses import dataclass
|
|||||||
DEFAULT_MODEL = "SD-1.5"
|
DEFAULT_MODEL = "SD-1.5"
|
||||||
DEFAULT_SAMPLER = "k_dpmpp_2m"
|
DEFAULT_SAMPLER = "k_dpmpp_2m"
|
||||||
|
|
||||||
|
DEFAULT_NEGATIVE_PROMPT = (
|
||||||
|
"Ugly, duplication, duplicates, mutilation, deformed, mutilated, mutation, twisted body, disfigured, bad anatomy, "
|
||||||
|
"out of frame, extra fingers, mutated hands, "
|
||||||
|
"poorly drawn hands, extra limbs, malformed limbs, missing arms, extra arms, missing legs, extra legs, mutated hands, "
|
||||||
|
"extra hands, fused fingers, missing fingers, extra fingers, long neck, small head, closed eyes, rolling eyes, "
|
||||||
|
"weird eyes, smudged face, blurred face, poorly drawn face, mutation, mutilation, cloned face, strange mouth, "
|
||||||
|
"grainy, blurred, blurry, writing, calligraphy, signature, text, watermark, bad art,"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ModelConfig:
|
class ModelConfig:
|
||||||
|
@ -94,6 +94,7 @@ class ImaginePrompt:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
prompt=None,
|
prompt=None,
|
||||||
|
negative_prompt=config.DEFAULT_NEGATIVE_PROMPT,
|
||||||
prompt_strength=7.5,
|
prompt_strength=7.5,
|
||||||
init_image=None, # Pillow Image, LazyLoadingImage, or filepath str
|
init_image=None, # Pillow Image, LazyLoadingImage, or filepath str
|
||||||
init_image_strength=0.3,
|
init_image_strength=0.3,
|
||||||
@ -113,16 +114,11 @@ class ImaginePrompt:
|
|||||||
tile_mode=False,
|
tile_mode=False,
|
||||||
model=config.DEFAULT_MODEL,
|
model=config.DEFAULT_MODEL,
|
||||||
):
|
):
|
||||||
prompt = prompt if prompt is not None else ""
|
|
||||||
fix_faces_fidelity = (
|
self.prompts = self.process_prompt_input(prompt)
|
||||||
fix_faces_fidelity if fix_faces_fidelity else self.DEFAULT_FACE_FIDELITY
|
self.negative_prompt = self.process_prompt_input(negative_prompt)
|
||||||
)
|
|
||||||
if isinstance(prompt, str):
|
|
||||||
self.prompts = [WeightedPrompt(prompt, 1)]
|
|
||||||
else:
|
|
||||||
self.prompts = prompt
|
|
||||||
self.prompts.sort(key=lambda p: p.weight, reverse=True)
|
|
||||||
self.prompt_strength = prompt_strength
|
self.prompt_strength = prompt_strength
|
||||||
|
|
||||||
if isinstance(init_image, str):
|
if isinstance(init_image, str):
|
||||||
init_image = LazyLoadingImage(filepath=init_image)
|
init_image = LazyLoadingImage(filepath=init_image)
|
||||||
|
|
||||||
@ -142,7 +138,9 @@ class ImaginePrompt:
|
|||||||
self.width = width
|
self.width = width
|
||||||
self.upscale = upscale
|
self.upscale = upscale
|
||||||
self.fix_faces = fix_faces
|
self.fix_faces = fix_faces
|
||||||
self.fix_faces_fidelity = fix_faces_fidelity
|
self.fix_faces_fidelity = (
|
||||||
|
fix_faces_fidelity if fix_faces_fidelity else self.DEFAULT_FACE_FIDELITY
|
||||||
|
)
|
||||||
self.sampler_type = sampler_type.lower()
|
self.sampler_type = sampler_type.lower()
|
||||||
self.conditioning = conditioning
|
self.conditioning = conditioning
|
||||||
self.mask_prompt = mask_prompt
|
self.mask_prompt = mask_prompt
|
||||||
@ -190,6 +188,15 @@ class ImaginePrompt:
|
|||||||
"sampler_type": self.sampler_type,
|
"sampler_type": self.sampler_type,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def process_prompt_input(self, prompt_input):
|
||||||
|
prompt_input = prompt_input if prompt_input is not None else ""
|
||||||
|
|
||||||
|
if isinstance(prompt_input, str):
|
||||||
|
prompt_input = [WeightedPrompt(prompt_input, 1)]
|
||||||
|
|
||||||
|
prompt_input.sort(key=lambda p: p.weight, reverse=True)
|
||||||
|
return prompt_input
|
||||||
|
|
||||||
|
|
||||||
class ExifCodes:
|
class ExifCodes:
|
||||||
"""https://www.awaresystems.be/imaging/tiff/tifftags/baseline.html"""
|
"""https://www.awaresystems.be/imaging/tiff/tifftags/baseline.html"""
|
||||||
|
Before Width: | Height: | Size: 311 KiB After Width: | Height: | Size: 320 KiB |
Before Width: | Height: | Size: 279 KiB After Width: | Height: | Size: 279 KiB |
Before Width: | Height: | Size: 590 KiB After Width: | Height: | Size: 572 KiB |
Before Width: | Height: | Size: 570 KiB After Width: | Height: | Size: 562 KiB |
Before Width: | Height: | Size: 540 KiB After Width: | Height: | Size: 587 KiB |
Before Width: | Height: | Size: 584 KiB After Width: | Height: | Size: 564 KiB |
Before Width: | Height: | Size: 617 KiB After Width: | Height: | Size: 580 KiB |
Before Width: | Height: | Size: 568 KiB After Width: | Height: | Size: 566 KiB |
Before Width: | Height: | Size: 577 KiB After Width: | Height: | Size: 602 KiB |
Before Width: | Height: | Size: 599 KiB After Width: | Height: | Size: 566 KiB |
Before Width: | Height: | Size: 573 KiB After Width: | Height: | Size: 576 KiB |
Before Width: | Height: | Size: 571 KiB After Width: | Height: | Size: 562 KiB |
Before Width: | Height: | Size: 588 KiB After Width: | Height: | Size: 570 KiB |
Before Width: | Height: | Size: 550 KiB After Width: | Height: | Size: 557 KiB |
Before Width: | Height: | Size: 261 KiB After Width: | Height: | Size: 257 KiB |
Before Width: | Height: | Size: 239 KiB After Width: | Height: | Size: 236 KiB |
Before Width: | Height: | Size: 258 KiB After Width: | Height: | Size: 257 KiB |
Before Width: | Height: | Size: 241 KiB After Width: | Height: | Size: 240 KiB |
Before Width: | Height: | Size: 241 KiB After Width: | Height: | Size: 239 KiB |
Before Width: | Height: | Size: 238 KiB After Width: | Height: | Size: 236 KiB |
Before Width: | Height: | Size: 255 KiB After Width: | Height: | Size: 255 KiB |
Before Width: | Height: | Size: 237 KiB After Width: | Height: | Size: 235 KiB |
Before Width: | Height: | Size: 251 KiB After Width: | Height: | Size: 252 KiB |
Before Width: | Height: | Size: 239 KiB After Width: | Height: | Size: 236 KiB |
Before Width: | Height: | Size: 239 KiB After Width: | Height: | Size: 237 KiB |
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 259 KiB |
Before Width: | Height: | Size: 388 KiB After Width: | Height: | Size: 387 KiB |
Before Width: | Height: | Size: 337 KiB After Width: | Height: | Size: 344 KiB |
Before Width: | Height: | Size: 383 KiB After Width: | Height: | Size: 385 KiB |
Before Width: | Height: | Size: 341 KiB After Width: | Height: | Size: 348 KiB |
Before Width: | Height: | Size: 341 KiB After Width: | Height: | Size: 350 KiB |
Before Width: | Height: | Size: 338 KiB After Width: | Height: | Size: 346 KiB |
Before Width: | Height: | Size: 377 KiB After Width: | Height: | Size: 381 KiB |
Before Width: | Height: | Size: 330 KiB After Width: | Height: | Size: 337 KiB |
Before Width: | Height: | Size: 368 KiB After Width: | Height: | Size: 372 KiB |
Before Width: | Height: | Size: 337 KiB After Width: | Height: | Size: 345 KiB |
Before Width: | Height: | Size: 338 KiB After Width: | Height: | Size: 342 KiB |
Before Width: | Height: | Size: 389 KiB After Width: | Height: | Size: 391 KiB |
Before Width: | Height: | Size: 263 KiB After Width: | Height: | Size: 269 KiB |
Before Width: | Height: | Size: 260 KiB After Width: | Height: | Size: 264 KiB |
Before Width: | Height: | Size: 252 KiB After Width: | Height: | Size: 259 KiB |
Before Width: | Height: | Size: 241 KiB After Width: | Height: | Size: 241 KiB |
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 275 KiB |
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 268 KiB |
Before Width: | Height: | Size: 254 KiB After Width: | Height: | Size: 259 KiB |
Before Width: | Height: | Size: 262 KiB After Width: | Height: | Size: 267 KiB |
Before Width: | Height: | Size: 271 KiB After Width: | Height: | Size: 274 KiB |
Before Width: | Height: | Size: 248 KiB After Width: | Height: | Size: 254 KiB |
Before Width: | Height: | Size: 266 KiB After Width: | Height: | Size: 275 KiB |
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 269 KiB |
Before Width: | Height: | Size: 256 KiB After Width: | Height: | Size: 262 KiB |
Before Width: | Height: | Size: 266 KiB After Width: | Height: | Size: 278 KiB |
Before Width: | Height: | Size: 262 KiB After Width: | Height: | Size: 268 KiB |
Before Width: | Height: | Size: 256 KiB After Width: | Height: | Size: 260 KiB |
Before Width: | Height: | Size: 265 KiB After Width: | Height: | Size: 275 KiB |
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 268 KiB |
Before Width: | Height: | Size: 255 KiB After Width: | Height: | Size: 259 KiB |
Before Width: | Height: | Size: 240 KiB After Width: | Height: | Size: 240 KiB |
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 266 KiB |
Before Width: | Height: | Size: 271 KiB After Width: | Height: | Size: 273 KiB |
Before Width: | Height: | Size: 249 KiB After Width: | Height: | Size: 254 KiB |
Before Width: | Height: | Size: 240 KiB After Width: | Height: | Size: 240 KiB |
Before Width: | Height: | Size: 263 KiB After Width: | Height: | Size: 274 KiB |
Before Width: | Height: | Size: 262 KiB After Width: | Height: | Size: 266 KiB |
Before Width: | Height: | Size: 253 KiB After Width: | Height: | Size: 258 KiB |
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 266 KiB |
Before Width: | Height: | Size: 270 KiB After Width: | Height: | Size: 271 KiB |
Before Width: | Height: | Size: 247 KiB After Width: | Height: | Size: 250 KiB |
Before Width: | Height: | Size: 240 KiB After Width: | Height: | Size: 240 KiB |
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 274 KiB |
Before Width: | Height: | Size: 264 KiB After Width: | Height: | Size: 268 KiB |
Before Width: | Height: | Size: 254 KiB After Width: | Height: | Size: 259 KiB |
Before Width: | Height: | Size: 265 KiB After Width: | Height: | Size: 275 KiB |
Before Width: | Height: | Size: 263 KiB After Width: | Height: | Size: 268 KiB |
Before Width: | Height: | Size: 254 KiB After Width: | Height: | Size: 258 KiB |
Before Width: | Height: | Size: 240 KiB After Width: | Height: | Size: 240 KiB |
Before Width: | Height: | Size: 263 KiB After Width: | Height: | Size: 274 KiB |
Before Width: | Height: | Size: 262 KiB After Width: | Height: | Size: 265 KiB |
Before Width: | Height: | Size: 253 KiB After Width: | Height: | Size: 261 KiB |
Before Width: | Height: | Size: 241 KiB After Width: | Height: | Size: 241 KiB |
Before Width: | Height: | Size: 558 KiB After Width: | Height: | Size: 556 KiB |
Before Width: | Height: | Size: 357 KiB After Width: | Height: | Size: 364 KiB |
Before Width: | Height: | Size: 367 KiB After Width: | Height: | Size: 363 KiB |
Before Width: | Height: | Size: 887 KiB After Width: | Height: | Size: 881 KiB |
Before Width: | Height: | Size: 392 KiB After Width: | Height: | Size: 360 KiB |
Before Width: | Height: | Size: 432 KiB After Width: | Height: | Size: 386 KiB |
Before Width: | Height: | Size: 425 KiB After Width: | Height: | Size: 379 KiB |
Before Width: | Height: | Size: 787 KiB After Width: | Height: | Size: 772 KiB |
Before Width: | Height: | Size: 386 KiB After Width: | Height: | Size: 371 KiB |
Before Width: | Height: | Size: 456 KiB After Width: | Height: | Size: 417 KiB |
Before Width: | Height: | Size: 459 KiB After Width: | Height: | Size: 418 KiB |
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.0 MiB |
Before Width: | Height: | Size: 403 KiB After Width: | Height: | Size: 415 KiB |
Before Width: | Height: | Size: 437 KiB After Width: | Height: | Size: 397 KiB |
Before Width: | Height: | Size: 425 KiB After Width: | Height: | Size: 397 KiB |