CompVis / stable-diffusion

A latent text-to-image diffusion model
https://ommer-lab.com/research/latent-diffusion-models/
Other
67.81k stars 10.11k forks source link

Seamless Tileables Texture (Tiling) #250

Open denizbinay opened 2 years ago

denizbinay commented 2 years ago

I found this code on gitlab to make the output seamless tileable. It works with diffusers. But unfortunately I don't know how to include it here. Any Ideas?

import torch

def patch_conv(cls):
    init = cls.__init__
    def __init__(self, *args, **kwargs):
        return init(self, *args, **kwargs, padding_mode='circular')
    cls.__init__ = __init__

patch_conv(torch.nn.Conv2d)

from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
pipe.to("cuda")
pipe("a photograph of an astronaut riding a horse")["sample"][0].save("output.png")
denizbinay commented 2 years ago

Okay, here it is. Add this Code to /notebooks/stable-diffusion/scripts/img2img.py at line 34.

def patch_conv(klass):
    init = klass.__init__
    def __init__(self, *args, **kwargs):
        return init(self, *args, **kwargs, padding_mode='circular')
    klass.__init__ = __init__

for klass in [torch.nn.Conv2d, torch.nn.ConvTranspose2d]:
    patch_conv(klass)

Source: https://github.com/sd-webui/stable-diffusion-webui/discussions/224#discussioncomment-3494819