How to use batch prediction in Diffusers.StableDiffusionXLImg2ImgPipeline library

33 Views Asked by At

I'm currently exploring the StableDiffusion Image to Image library within HuggingFace. My goal is to generate images similar to the ones I have stored in a folder. Currently, I'm using the following code snippet:

import torch
from diffusers.utils import load_image
from diffusers import StableDiffusionXLImg2ImgPipeline

pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
)

pipe = pipe.to("cuda")
url = "MyImages\ImageList\998.jpg"

init_image = load_image(url).convert("RGB")
prompt = "Give me a similar image like this"
image = pipe(prompt, image=init_image).images

this code requires me to generate each image manually, one by one. I can write a for loop like this -

all_images = os.listdir('MyImages\ImageList\')
for img in all_images:
  ...
  ...

I'm considering the possibility of processing images in batches rather than individually. Is there a method or a library within HuggingFace that allows for batch processing of images to generate similar ones?

0

There are 0 best solutions below