I have a problem when using diffuser to Img2Img,what i have done is following:
- First use ffmpeg to convert the reference video into an image;
- Then use GFPGAN to repair the picture in high definition;
- Use Img2Img to transform the character’s image;
- Use ffmpeg to merge images into videos
the result seems blink,you can see the result video
what’s did i miss?
my code is
from diffusers import StableDiffusionImg2ImgPipeline
from diffusers import DPMSolverMultistepScheduler
import torch
from PIL import Image
import os
model_path = 'realisticVisionV60B1_v51VAE.safetensors'
pipe = StableDiffusionImg2ImgPipeline.from_single_file(
model_path,
torch_dtype=torch.float32,
safety_check=True,
)
pipe = pipe.to("cuda")
#prompt = "a woman in a yellow suit is on a news set with a laptop computer in front of her and a blue background"
prompt = "a woman in a yellow suit is on a news set with a laptop computer in front of her"
negtive_prompt = "earrings,wrinkle,forehead lines,blurry,low quality,low resolution"
seed_id = 3563236128
num_inference_steps = 10
guidance_scale = 5
strength = 0.3
initial_noise_multiplier = 1
generator = torch.Generator("cuda").manual_seed(seed_id)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(
pipe.scheduler.config,
algorithm_type="sde-dpmsolver++",
use_karras_sigmas=True,
euler_at_finale=True,
)
Input_Folder = "SourcePngs"
#
for root, dirs, files in os.walk(Input_Folder):
for file in files:
if file.endswith(".png"):
ImgName = file.split(".")[0]
ImgFullPath = os.path.join(root, file)
#
Img = Image.open(ImgFullPath).convert("RGB")
#
image = pipe(
prompt=prompt,
negtive_prompt=negtive_prompt,
generator=generator,
num_inference_steps=num_inference_steps,
width=1100,
height=1200,
num_images_per_prompt=1,
guidance_scale=guidance_scale,
strength=strength,
initial_noise_multiplier=initial_noise_multiplier,
image=Img).images[0]
image.save(ImgFullPath)
print("Image Saved to :", ImgFullPath)