最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Hugging Face Diffusion Model - Adding object to an existing photo - Stack Overflow

programmeradmin1浏览0评论

I am playing around with Huggingface library. I wanted to add an object to an existing photo. I supplied the diffusion pipeline and prompt it to add the object.

The photo I supplied contains only the face of my dog. The result was just an original photo with some noise, nothing remotely looks like a gold chain wad added.

Is this the correct and sufficient way to achieve what I want?

Below is the code:

from diffusers import StableDiffusionImg2ImgPipeline
import torch
from PIL import Image
import matplotlib.pyplot as plt

# Load img2img pipeline
device = "mps" if torch.backends.mps.is_available() else "cpu"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-2-1").to(device)

# Load your photo
init_image = Image.open("/Users/myUser/Downloads/Meelo1.png").convert("RGB")
new_width = 512
idth_percent = (new_width / float(init_image.size[0]))  # Get the width percentage
new_height = int((float(init_image.size[1]) * float(width_percent)))
resized_image = init_image.resize((new_width, new_height), Image.Resampling.LANCZOS)
# Generate a new image based on your input photo
prompt = "A dog face wearing a thick gold chain"

image = pipe(prompt=prompt, image=resized_image, strength=0.3, num_inference_steps=200).images[0]
plt.imshow(image)
plt.axis("off")
plt.show()
发布评论

评论列表(0)

  1. 暂无评论