Upload layer_diff_dataset/test_inp_sd.py with huggingface_hub
Browse files
layer_diff_dataset/test_inp_sd.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import AutoPipelineForInpainting
|
| 2 |
+
from diffusers.utils import load_image
|
| 3 |
+
import torch
|
| 4 |
+
import os
|
| 5 |
+
from tqdm import tqdm
|
| 6 |
+
import cv2
|
| 7 |
+
from PIL import Image
|
| 8 |
+
|
| 9 |
+
pipe = AutoPipelineForInpainting.from_pretrained("../alpha_work/diffusers/stable-diffusion-xl-1.0-inpainting_", torch_dtype=torch.float16, variant="fp16").to("cuda")
|
| 10 |
+
# print('pipe',pipe)
|
| 11 |
+
# StableDiffusionXLInpaintPipeline
|
| 12 |
+
folder_path_0 = '../codes/Inpaint-Anything/results/0b6f9105fc'
|
| 13 |
+
folder_path = '../data/video_dataset/YoutubeVOS/train/mask/0b6f9105fc'
|
| 14 |
+
folder_path_ = 'YoutubeVOS/inp_preprocess_sd_0.9_base/0b6f9105fc'
|
| 15 |
+
os.makedirs(folder_path_,exist_ok=True)
|
| 16 |
+
file_list = os.listdir(folder_path)
|
| 17 |
+
file_list = [i for i in file_list if i.endswith('.png')]
|
| 18 |
+
file_list.sort()
|
| 19 |
+
# img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
|
| 20 |
+
# mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
prompt = "hazy background with nothing on"
|
| 24 |
+
generator = torch.Generator(device="cuda").manual_seed(0)
|
| 25 |
+
# base_image = Image.open(base_image_path).resize((1024, 1024))
|
| 26 |
+
|
| 27 |
+
pbar = tqdm(enumerate(file_list),total=len(file_list))
|
| 28 |
+
for i, image_name in pbar:
|
| 29 |
+
# if os.path.exists(os.path.join(folder_path_,image_name)):
|
| 30 |
+
# continue
|
| 31 |
+
image_path = os.path.join(folder_path_0,image_name)
|
| 32 |
+
mask_path = os.path.join(folder_path,image_name)
|
| 33 |
+
image = Image.open(image_path).resize((1024, 1024))
|
| 34 |
+
mask_image = Image.open(mask_path).resize((1024, 1024))
|
| 35 |
+
# image = cv2.resize(cv2.imread(image_path),(1024,1024))
|
| 36 |
+
# mask_image = cv2.resize(cv2.imread(mask_path,cv2.IMREAD_GRAYSCALE),(1024,1024))
|
| 37 |
+
# image = load_image(img_url).resize((1024, 1024))
|
| 38 |
+
# mask_image = load_image(mask_url).resize((1024, 1024))
|
| 39 |
+
if i==0:
|
| 40 |
+
base_image = image
|
| 41 |
+
image_out = pipe(
|
| 42 |
+
prompt=prompt,
|
| 43 |
+
image=image,
|
| 44 |
+
base_image=base_image,
|
| 45 |
+
mask_image=mask_image,
|
| 46 |
+
guidance_scale=8.0,
|
| 47 |
+
num_inference_steps=20, # steps between 15 and 30 work well for us
|
| 48 |
+
strength=0.9, # make sure to use `strength` below 1.0
|
| 49 |
+
generator=generator,
|
| 50 |
+
).images[0]
|
| 51 |
+
image_out.save(os.path.join(folder_path_,image_name))
|
| 52 |
+
if i==0:
|
| 53 |
+
base_image = image_out
|