Upload layer_diff_dataset/test_inp_1 copy 4.py with huggingface_hub
Browse files
layer_diff_dataset/test_inp_1 copy 4.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import torch
|
| 3 |
+
import os
|
| 4 |
+
import json
|
| 5 |
+
from tqdm import tqdm
|
| 6 |
+
from modelscope.outputs import OutputKeys
|
| 7 |
+
from modelscope.pipelines import pipeline
|
| 8 |
+
from modelscope.utils.constant import Tasks
|
| 9 |
+
|
| 10 |
+
# input_location = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_inpainting/image_inpainting_1.png'
|
| 11 |
+
# input_mask_location = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_inpainting/image_inpainting_mask_1.png'
|
| 12 |
+
prompt = 'hazy background with nothing on'
|
| 13 |
+
|
| 14 |
+
folder_path_0 = '/mnt/workspace/workgroup/sihui.jsh/layer_diff_dataset/train/im_resized'
|
| 15 |
+
folder_path = '/mnt/workspace/workgroup/sihui.jsh/layer_diff_dataset/train/gt_dilate'
|
| 16 |
+
folder_path_ = '/mnt/workspace/workgroup/sihui.jsh/layer_diff_dataset/train/gt_inp_iic_gt_dilate'
|
| 17 |
+
os.makedirs(folder_path_,exist_ok=True)
|
| 18 |
+
file_list = os.listdir(folder_path)
|
| 19 |
+
file_list = [i for i in file_list if i.endswith('.png')]
|
| 20 |
+
file_list.sort()
|
| 21 |
+
|
| 22 |
+
pbar = tqdm(enumerate(file_list),total=len(file_list))
|
| 23 |
+
# with open('/mnt/workspace/workgroup/sihui.jsh/layer_diff_dataset/train/im_rgba.json', 'r') as file:
|
| 24 |
+
# data = json.load(file)
|
| 25 |
+
image_inpainting = pipeline(
|
| 26 |
+
Tasks.image_inpainting,
|
| 27 |
+
model='/mnt/workspace/workgroup/sihui.jsh/alpha_work/diffusers/iic/cv_stable-diffusion-v2_image-inpainting_base',
|
| 28 |
+
device='cuda:1',
|
| 29 |
+
torch_dtype=torch.float16,
|
| 30 |
+
enable_attention_slicing=True)
|
| 31 |
+
for i, image_name in pbar:
|
| 32 |
+
if os.path.exists(os.path.join(folder_path_,image_name)):
|
| 33 |
+
continue
|
| 34 |
+
# if i<1000:
|
| 35 |
+
# continue
|
| 36 |
+
if i<=2000:
|
| 37 |
+
continue
|
| 38 |
+
elif i > 2500:
|
| 39 |
+
break
|
| 40 |
+
|
| 41 |
+
# if i==1:
|
| 42 |
+
# break
|
| 43 |
+
# gt_name = data[i]["images"].split('/')[-1]
|
| 44 |
+
# print(image_name,gt_name)
|
| 45 |
+
# prompt = data[i]["prompt_fg"]
|
| 46 |
+
# print(prompt)
|
| 47 |
+
|
| 48 |
+
# mask_image = load_image(os.path.join(folder_path,image_name)).resize((512, 512))
|
| 49 |
+
# image = load_image(os.path.join(folder_path_0,image_name.split('.png')[0]+'.jpg')).resize((512, 512))
|
| 50 |
+
|
| 51 |
+
input = {
|
| 52 |
+
'image': os.path.join(folder_path_0,image_name.split('.png')[0]+'.jpg'),
|
| 53 |
+
'mask': os.path.join(folder_path,image_name),
|
| 54 |
+
'prompt': prompt
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
output = image_inpainting(input)[OutputKeys.OUTPUT_IMG]
|
| 58 |
+
cv2.imwrite(os.path.join(folder_path_,image_name), output)
|