mindspore-lab / mindone

one for all, Optimal generator with No Exception
Apache License 2.0
328 stars 62 forks source link

feat(diffusers): StableDiffusionImg2ImgPipeline implementation #476

Closed TamirBaydasov closed 1 month ago

TamirBaydasov commented 2 months ago

What does this PR do?

Fixes # (issue)

Adds # (feature)

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR.

@xxx

TamirBaydasov commented 2 months ago

Demo used to check image quality:

import mindspore as ms
import requests
from PIL import Image
from io import BytesIO
from mindone.diffusers import StableDiffusionImg2ImgPipeline

pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
            "runwayml/stable-diffusion-v1-5",
            mindspore_dtype=ms.float32,
            use_safetensors=True,
            )

prompt = "a portrait of a dog wearing a pearl earring"
url = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/0f/1665_Girl_with_a_Pearl_Earring.jpg/800px-1665_Girl_with_a_Pearl_Earring.jpg"

response = requests.get(url, verify=False)
image = Image.open(BytesIO(response.content)).convert("RGB")
image.thumbnail((768, 768))
ms.set_context(device_target='GPU', mode=0)
image = pipe(
            prompt=prompt,
            image=image,
            num_inference_steps=50,
            strength=0.75,
            guidance_scale=10.5
            )[0][0]
TamirBaydasov commented 1 month ago

Closed due to merge with https://github.com/mindspore-lab/mindone/pull/474