Replies: 19 comments 11 replies
-
is this related? horizontal/vertical tiling https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts#asymmetric-tiling |
Beta Was this translation helpful? Give feedback.
-
Apparently I need to overload one of the functions responsible for image processing each step and then manipulate the numpy array if I want to implement "force symmetry". I think cutting the picture in half and mirroring one half every n steps or at some specific step is a good idea. I will dwell on it. |
Beta Was this translation helpful? Give feedback.
-
Update. I was able to implement the symmetry of the generated noise and apparently this affects the composition of the image a little. This should work with all samplers. Below are two examples. The seed is the same, the prompt was "face". In the first example I applied noise symmetry by simply reflecting a copy of the tensor and adding the two halves. If you are interested in research in this direction - I invite you to join me and share your experience. At the moment, I'm struggling with applying symmetry every n steps in the generation process. I still could not figure out how to correctly decode and encode the latent, related question here: #2543 I will be glad to any suggestions. upd. Also, it seems to me that applying such a technique to the generated noise is not the best option. I can't explain why, I just feel it. The images on which the neural network was trained are in most cases asymmetric, and the noise is random by definition. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Proof of concept script. There is still a lot of work to be done. Currently does not support generating multiple images at a time https://gist.github.com/1ort/2fe6214cf1abe4c07087aac8d91d0d8a |
Beta Was this translation helpful? Give feedback.
-
Update. Implemented new "apply_symmetry" method, which seems a little bit better |
Beta Was this translation helpful? Give feedback.
-
@1ort trying your script alot of images I'm getting are hazy. The results you've gotten look nice, would you tell me what settings you've used? Maybe make a writeup and repo, so we can link this better. |
Beta Was this translation helpful? Give feedback.
-
This could be very useful for designing character reference sheets before finalizing the design with inpainting, good work implementing a proof of concept so quickly. |
Beta Was this translation helpful? Give feedback.
-
For ancestral samplers there's another option of messing with the KDiffusionSampler.callback_state callback, what you have as mirrored blending, or just flipping the image on alternate steps both work, but only for ancestral samplers, and it eventually breaks denosing resulting in excessive blur. def callback_state(self, d):
step = d['i']
latent = d["denoised"]
store_latent(latent)
self.last_latent = latent
if step < state.sampling_steps*opts.sampler_mirroring_fraction:
if opts.sampler_mirroring_method == 'Alternate Sample Flip':
d["x"][:, :, :, :] = torch.flip(d["x"], [3])
elif opts.sampler_mirroring_method == 'Avergage Flipped Copy':
d["x"][:, :, :, :] = (torch.flip(d["x"], [3]) + d["x"])/2
if self.stop_at is not None and step > self.stop_at:
raise InterruptedException
state.sampling_step = step
shared.total_tqdm.update() Can be quite subtle if you keep the steps it ends at low: |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Small PR offered to open up a call-back into CFGDenoiser here: #4021 With a demo-script if that lands: https://gist.github.com/dfaker/ac031e87174a94d8a170d897caac9ff6 But much more hackery is in theory possible, like overlaying alternate or swapping totally different latent image representations or boosting contrast, hue and vignetting in image latent representations. |
Beta Was this translation helpful? Give feedback.
-
To @1ort and @dfaker I’m using a 2060/6GB, with COMMANDLINE_ARGS set to: --medvram --xformers --listen --ckpt "D:\stable-diffusion-webui-master\models\Stable-diffusion\v1-5-pruned-emaonly.ckpt" Both “Force symmetry” and “Mirroring” show up in txt2img’s Script list. Decided to have a go with “Force symmetry” in txt2img anyway. I get an output pic with, erm :-), something done to it all right. I’ll need to play with parameters to get a feel for them. My output folder also gets a noised/blurred pic during the generation. I don’t have any of the “Save a copy of image before” boxes ticked in Settings. Setting Script back to “None” and generating a new txt2img works fine. Using the “Mirroring” script in txt2img I also get some fascinating output images, although no extra saved interim image this time. Setting Script back to “None” and generating a new txt2img does not work correctly. I get the same image generated (I’m using fixed seed) as when “Mirroring” was active. In fact all txt2img generations with any prompt are now affected by “Mirroring” If I now select “Force Symmetry” again, what I get is an output image that seems to have the effects of “Force Symmetry” and “Mirroring” combined! The only way I’ve found to stop “Mirroring” taking effect is to ctrl-c out of the console and restart the webui. I have a 2nd machine with a 1650s/4GB, same webui=d98eace, and the same thing happens. Am I doing something stupid? It wouldn’t be the first time :-) |
Beta Was this translation helpful? Give feedback.
-
Sounds like the callbacks aren't being removed when the script is switched away from, which I thought was a feature of the script runner, I'll take a look. |
Beta Was this translation helpful? Give feedback.
-
Hi, I tried the script and it's really good, love the results it's giving. Thanks for working on it! I would like to combine it with the x/y plot script to explore some combinations, any idea how that could work? Or any plans to move it to a plugin so it can be used separately from other scripts? |
Beta Was this translation helpful? Give feedback.
-
Glad you're enjoying it! Since this requires a callback the easiest way I can see is to move that code into a custom x/y plot script. |
Beta Was this translation helpful? Give feedback.
-
As for the extension conversion, the repo is converted to that format now, and defaults to 'None' mirroring. |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for the extension, I've been using it a lot... I found a bug today: when using high-res fix the mirroring is applied again when it starts generating the larger image, basically breaking the original image and defeating the purpose of the high res fix. |
Beta Was this translation helpful? Give feedback.
-
Fascinating thread and interesting code examples! All these approaches depend on "symmetrising" the latents, either by averaging, copying one half to the other side or transforming the latent space (e.g. flipping). This seems to work well when symmetry is only imposed during early iterations, while for later iterations the images become abstract or smeared out. I was wondering if you have ideas how the symmetry could be baked directly into the denoising process of Stable Diffusion, somehow forcing it to converge to symmetric solutions during the image generation process without disturbing the latent space representation. |
Beta Was this translation helpful? Give feedback.
-
Hi, I need to apply this exact use-case but not sure how to apply it to SDXL model directly without using a1111? |
Beta Was this translation helpful? Give feedback.
-
Hello! I want to write a custom script that will potentially allow you to get images with a choice of horizontal, vertical or other symmetry.
I know that I can prompt this, but I want to get more predictable behavior. In addition, the neural network does not understand horizontal symmetry well, you don’t even have to think about angular and their combinations.
I am currently considering several options:
Now I am actively studying the code, but many points are poorly documented or not documented.
Which way should I look?
Perhaps, Someone has already tried to implement this and it worked or failed. This information is also of interest to me.
upd. I settled on this code and it seems to work. Examples below. There is still a lot of work to be done. Currently does not support generating multiple images at a time and various bugs and crashes are possible
https://gist.github.com/1ort/2fe6214cf1abe4c07087aac8d91d0d8a
Beta Was this translation helpful? Give feedback.
All reactions