nicolai256 / Stable-textual-inversion_win

MIT License
241 stars 43 forks source link

a new approach conditioning prompts (personalized.py) #30

Open ciaobnsr opened 2 years ago

ciaobnsr commented 2 years ago

in the personalized.py when it comes to use prompts for conditioning i've seen a new approach that works per-image. ive seen it used on the original rinongal so your code might be different:

"If you want to change your training to be done on sample image specific prompts rather than random prompts like "a photo of *", then in personalized.py you can just change text = random.choice(imagenet_templates_small).format( placeholder_string ) to imgName = Path(imgPath).stem # filename without directories or extension text = imgName.replace("@", "{}" ).format( placeholder_string ) # could maybe just be .replace("@", placeholder_string)

And write your prompt in your training image filenames with @ for the embedding (e.g. a closeup portrait photo of @ from the left, against a beige background.png). It seems to help generate an embedding which also has to work with other parts of the prompt, rather than just training an embedding for a physical object which isn't much influenced by the prompt"

is there a way to make this approach work with this repo, and if yes will it really help to achieve a better result? (im guessing it would find identity faster and keep a better editability but it's just guesses)

CodeExplode commented 2 years ago

Heya just a slight update since I wrote this code in discord, the second line can just be:

text = text.replace("@", placeholder_string )

I'm not entirely sure whether it's helping or not. My idea is that it requires the embedding to also work in the context of the other prompt words, which hopefully maintains more editability. With just the embedding by itself as the prompt you may get decent results much faster, but it's an embedding which perhaps doesn't consider (or activate weights which interact with) other words around it, and acts more like a static object model.