Nota-NetsPresso / BK-SDM

A Compressed Stable Diffusion for Efficient Text-to-Image Generation [ECCV'24]
Other
238 stars 16 forks source link

Is there someway to test Img2Img? #43

Closed bigmover closed 8 months ago

bokyeong1015 commented 9 months ago

Hi, our models are applicable to text-guided image-to-image translation using StableDiffusionImg2ImgPipeline. Please check out the example below if you are interested.

image

Example from Hugging Face:

import requests
import torch
from PIL import Image
from io import BytesIO

from diffusers import StableDiffusionImg2ImgPipeline

device = "cuda"
# model_id_or_path = "runwayml/stable-diffusion-v1-5"
# file_name = "output_sd1.5"

model_id_or_path = "nota-ai/bk-sdm-base"
file_name = "output_bk-sdm-base"

pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
pipe = pipe.to(device)

url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"

response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")
init_image = init_image.resize((768, 512))
init_image.save("input.png")

prompt = "A fantasy landscape, trending on artstation"

images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images
images[0].save(f"{file_name}.png")