如何定义提示权重以适用于huggingface的diffusers.StableDiffusionInpaintPipeline?

huangapple go评论57阅读模式
英文:

How to define prompt weights to huggingface's diffusers.StableDiffusionInpaintPipeline?

问题

我正在调整一个Python脚本,使用扩散修复管道来实现自定义视频生成的想法。

我想逐渐调整提示中某些单词的权重。

据我了解,参数prompt_embeds正是我需要的。

我无法弄清楚如何定义这个参数。有人可以提供一个示例吗?

我知道有一些框架可以使用以下语法为某些单词添加权重:

"This is a SD prompt with plus 50% weight added to the last (word:1.5)"

这也是一个很好的解决方案,但它不适用于diffusers.StableDiffusionInpaintPipeline。

英文:

I am tweaking a python script using diffusers inpainting pipeline for a custom video generation idea.

I would like to gradually shift the weights of certain words in the prompt.

As I understand the argument prompt_embeds is exactly what i need.

I could not figure out how to define this argument. Can someone pls provide an example?

I know there are frameworks out there where you can just add weights to certain words with the following syntax:

"This is a SD prompt with plus 50% weight added to the last (word:1.5)"

This would be a great solution as well however this does not work with diffusers.StableDiffusionInpaintPipeline

答案1

得分: 1

来自原始库的示例:

from diffusers import StableDiffusionPipeline
from compel import Compel

pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
compel = Compel(tokenizer=pipeline.tokenizer, text_encoder=pipeline.text_encoder)

# upweight "ball"
prompt = "a cat playing with a ball++ in the forest"
conditioning = compel.build_conditioning tensor(prompt)
# 或者:conditioning = compel([prompt])

# 生成图像
images = pipeline(prompt_embeds=conditioning, num_inference_steps=20).images
images[0].save("image.jpg")

因此,如您所见,您应该添加 ++------- 等等。
对于您的情况,应该是像这样 “这是一个具有加权值为50%的SD提示,添加到最后一个单词+++++”。您也可以调整子提示的权重:“富有描述性的(子提示在这里)++++提示”

英文:

Example from the original repo of Compel library:

from diffusers import StableDiffusionPipeline
from compel import Compel

pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
compel = Compel(tokenizer=pipeline.tokenizer, text_encoder=pipeline.text_encoder)

# upweight "ball"
prompt = "a cat playing with a ball++ in the forest"
conditioning = compel.build_conditioning_tensor(prompt)
# or: conditioning = compel([prompt])

# generate image
images = pipeline(prompt_embeds=conditioning, num_inference_steps=20).images
images[0].save("image.jpg")

So, as you can see, you should add ++, or --, or ----- and so on.
For your case it would be like "This is a SD prompt with plus 50% weight added to the last word+++++". Also you can up\downweight subprompt: A rich and descriptive (a subprompt goes here)++++ prompt.

huangapple
  • 本文由 发表于 2023年2月6日 03:44:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355037.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定