Upload layer_diff_dataset/test_inp_4_try.py with huggingface_hub
Browse files
layer_diff_dataset/test_inp_4_try.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# 进行图片 impainting
|
| 11 |
+
|
| 12 |
+
# input_location = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_inpainting/image_inpainting_1.png'
|
| 13 |
+
# input_mask_location = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_inpainting/image_inpainting_mask_1.png'
|
| 14 |
+
prompt = 'hazy background with nothing on'
|
| 15 |
+
|
| 16 |
+
root_folder = '../data/aim-500'
|
| 17 |
+
jpeg_folder = os.path.join(root_folder,'original')
|
| 18 |
+
mask_folder = os.path.join(root_folder,'mask_dilate')
|
| 19 |
+
inp_folder = os.path.join(root_folder,'inpainting')
|
| 20 |
+
os.makedirs(inp_folder,exist_ok=True)
|
| 21 |
+
vid_list = os.listdir(jpeg_folder)
|
| 22 |
+
|
| 23 |
+
image_inpainting = pipeline(
|
| 24 |
+
Tasks.image_inpainting,
|
| 25 |
+
model='/mnt/workspace/workgroup/sihui.jsh/alpha_work/diffusers/iic/cv_stable-diffusion-v2_image-inpainting_base',
|
| 26 |
+
device='cuda:0',
|
| 27 |
+
torch_dtype=torch.float32,
|
| 28 |
+
enable_attention_slicing=True)
|
| 29 |
+
|
| 30 |
+
pbar = tqdm(enumerate(vid_list),total=len(vid_list))
|
| 31 |
+
for i, vid_name in pbar:
|
| 32 |
+
# if i<1000:
|
| 33 |
+
# continue
|
| 34 |
+
# if i==10:
|
| 35 |
+
# break
|
| 36 |
+
# folder_path_0 = 'YoutubeVOS/JPEGImages/0043f083b5'
|
| 37 |
+
folder_path_0 = os.path.join(jpeg_folder,vid_name)
|
| 38 |
+
folder_path = os.path.join(mask_folder,vid_name.replace('.jpg','.png'))
|
| 39 |
+
# folder_path = 'YoutubeVOS/mask_dilate/0043f083b5'
|
| 40 |
+
# folder_path_ = 'YoutubeVOS/inp/0043f083b5'
|
| 41 |
+
folder_path_ = os.path.join(inp_folder,vid_name)
|
| 42 |
+
# os.makedirs(folder_path_,exist_ok=True)
|
| 43 |
+
# file_list = os.listdir(folder_path)
|
| 44 |
+
# file_list = [i for i in file_list if i.endswith('.png')]
|
| 45 |
+
# file_list.sort()
|
| 46 |
+
|
| 47 |
+
# pbar = tqdm(enumerate(file_list),total=len(file_list))
|
| 48 |
+
# with open('/mnt/workspace/workgroup/sihui.jsh/layer_diff_dataset/train/im_rgba.json', 'r') as file:
|
| 49 |
+
# data = json.load(file)
|
| 50 |
+
|
| 51 |
+
# for i, image_name in enumerate(file_list):
|
| 52 |
+
# if os.path.exists(os.path.join(folder_path_,image_name)):
|
| 53 |
+
# continue
|
| 54 |
+
# last_idx = min(15,len(file_list)-1)
|
| 55 |
+
# if not (i == 0 or i == last_idx):
|
| 56 |
+
# continue
|
| 57 |
+
|
| 58 |
+
# mask_image = load_image(os.path.join(folder_path,image_name)).resize((512, 512))
|
| 59 |
+
# image = load_image(os.path.join(folder_path_0,image_name.split('.png')[0]+'.jpg')).resize((512, 512))
|
| 60 |
+
|
| 61 |
+
input = {
|
| 62 |
+
'image': folder_path_0,
|
| 63 |
+
'mask': folder_path,
|
| 64 |
+
'prompt': prompt
|
| 65 |
+
}
|
| 66 |
+
output = image_inpainting(input)[OutputKeys.OUTPUT_IMG]
|
| 67 |
+
# output = cv2.resize(output,(256,256))
|
| 68 |
+
cv2.imwrite(folder_path_, output)
|
| 69 |
+
# exit(0)
|