zjuJish commited on
Commit
c643006
·
verified ·
1 Parent(s): 952b893

Upload layer_diff_dataset/test_inp_sd copy.py with huggingface_hub

Browse files
layer_diff_dataset/test_inp_sd copy.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/0a2f2bd294'
13
+ folder_path_0 = 'YoutubeVOS/JPEGImages/0a2f2bd294'
14
+ folder_path = 'YoutubeVOS/mask_dilate/0a2f2bd294'
15
+ folder_path_ = 'YoutubeVOS/inp_sd_0.9_base/0a2f2bd294'
16
+ os.makedirs(folder_path_,exist_ok=True)
17
+ file_list = os.listdir(folder_path)
18
+ file_list = [i for i in file_list if i.endswith('.png')]
19
+ file_list.sort()
20
+ # img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
21
+ # mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
22
+
23
+
24
+ prompt = "hazy background with nothing on"
25
+ generator = torch.Generator(device="cuda").manual_seed(0)
26
+ # base_image = Image.open(base_image_path).resize((1024, 1024))
27
+
28
+ pbar = tqdm(enumerate(file_list),total=len(file_list))
29
+ for i, image_name in pbar:
30
+ # if os.path.exists(os.path.join(folder_path_,image_name)):
31
+ # continue
32
+ image_path = os.path.join(folder_path_0,image_name.split('.')[0]+'.jpg')
33
+ mask_path = os.path.join(folder_path,image_name)
34
+ image = Image.open(image_path).resize((1024, 1024))
35
+ mask_image = Image.open(mask_path).resize((1024, 1024))
36
+ # image = cv2.resize(cv2.imread(image_path),(1024,1024))
37
+ # mask_image = cv2.resize(cv2.imread(mask_path,cv2.IMREAD_GRAYSCALE),(1024,1024))
38
+ # image = load_image(img_url).resize((1024, 1024))
39
+ # mask_image = load_image(mask_url).resize((1024, 1024))
40
+ if i==0:
41
+ base_image = image
42
+ image_out = pipe(
43
+ prompt=prompt,
44
+ image=image,
45
+ base_image=base_image,
46
+ mask_image=mask_image,
47
+ guidance_scale=8.0,
48
+ num_inference_steps=20, # steps between 15 and 30 work well for us
49
+ strength=0.9, # make sure to use `strength` below 1.0
50
+ generator=generator,
51
+ ).images[0]
52
+ image_out.save(os.path.join(folder_path_,image_name))
53
+ if i==0:
54
+ base_image = image_out