cog-sdxl icon indicating copy to clipboard operation
cog-sdxl copied to clipboard

Height and width issue with SDXL image to image

Open rafationgson opened this issue 2 years ago • 3 comments

This issue is for stability-ai/sdxl model. When I use the model for img2img predictions and set custom width and height, the resulting output still follows the dimensions of the original image. For example I set the width to 1024 and height to 768 and the parameters are ignored. Can we add the width and height args to the img2img_pipe?

    if image and mask:
        print("inpainting mode")
        sdxl_kwargs["image"] = self.load_image(image)
        sdxl_kwargs["mask_image"] = self.load_image(mask)
        sdxl_kwargs["strength"] = prompt_strength
        sdxl_kwargs["width"] = width
        sdxl_kwargs["height"] = height
        pipe = self.inpaint_pipe
    elif image:
        print("img2img mode")
        sdxl_kwargs["image"] = self.load_image(image)
        sdxl_kwargs["strength"] = prompt_strength
        pipe = self.img2img_pipe
    else:
        print("txt2img mode")
        sdxl_kwargs["width"] = width
        sdxl_kwargs["height"] = height
        pipe = self.txt2img_pipe

rafationgson avatar Sep 07 '23 03:09 rafationgson

Found this issue today. There seem there two options. One resize the image before putting it replicate . Two create an alternative version of the repo and fix all the issues as the dev dont seem to be developing it anymore ( ノД`)シクシク…

JarvisSan22 avatar Nov 13 '23 23:11 JarvisSan22

My Current quck fix to this issue for a discord bot using replicate, is to use backblaze api to hold a resized image then use that for the imgurl. May help out

  • Backblaze api setup https://blog.teclado.com/python-file-upload-backblaze-b2/
def BB_imageFix(self,img_url,width,height):
        #Download discord image and resize 
        r=requests.get(img_url)
        image = Image.open(io.BytesIO(r.content))
        image=image.resize((width,height))
        file_name=f"placeholder_{os.path.basename(img_url)}"
        image.save(file_name)
        #Upload to backblaze 
        local_file = Path(file_name).resolve()
        metadata = {"key": "value"}
        uploaded_file = self.BB_bucket.upload_local_file(
                local_file=local_file,
                file_name=file_name,
                file_infos=metadata,
        )
        img_url=self.b2_api.get_download_url_for_fileid(uploaded_file.id_)
        os.remove(file_name) #Delete placeholder file from local 
        return img_url   

JarvisSan22 avatar Nov 14 '23 00:11 JarvisSan22

https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_img2img.py Going through the StableDiffusionXLImg2ImgPipeline that replicate uses there no width or height setting as these values seem to be based of the input image size but there is a target_size what could solve this issue

JarvisSan22 avatar Nov 14 '23 05:11 JarvisSan22