Spaces:
Running on Zero
Running on Zero
Copy inference/scripts/pick_cmp_rows.py
Browse files
inference/scripts/pick_cmp_rows.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
default_n_threads = 8
|
| 4 |
+
os.environ['OPENBLAS_NUM_THREADS'] = f"{default_n_threads}"
|
| 5 |
+
os.environ['MKL_NUM_THREADS'] = f"{default_n_threads}"
|
| 6 |
+
os.environ['OMP_NUM_THREADS'] = f"{default_n_threads}"
|
| 7 |
+
|
| 8 |
+
from utils.cv import *
|
| 9 |
+
from utils.io_utils import *
|
| 10 |
+
import shutil
|
| 11 |
+
|
| 12 |
+
lst = ['photo_2026-01-03_01-03-02', 'Generated Image January 03, 2026 - 12_47AM', 'Generated Image January 03, 2026 - 12_00AM']
|
| 13 |
+
|
| 14 |
+
dirs = ['tmp/cmp_part_extr/ours', 'workspace/datasets/testcaseall_output_woattn']
|
| 15 |
+
heads = ['ours', 'woattn']
|
| 16 |
+
|
| 17 |
+
save_dir = 'tmp/woattn_cmp'
|
| 18 |
+
|
| 19 |
+
for imgn in lst:
|
| 20 |
+
for ii, d in enumerate(dirs):
|
| 21 |
+
src_dir = osp.join(d, imgn)
|
| 22 |
+
from talking_head.preprocess import further_extr
|
| 23 |
+
further_extr(src_dir, rotate=False)
|
| 24 |
+
|
| 25 |
+
saved = save_dir
|
| 26 |
+
os.makedirs(saved, exist_ok=True)
|
| 27 |
+
|
| 28 |
+
if ii == 0:
|
| 29 |
+
src_img = np.array(Image.open(osp.join(src_dir, 'src_img.png')))
|
| 30 |
+
sz = src_img.shape[:2]
|
| 31 |
+
xyxy = np.array(cv2.boundingRect(cv2.findNonZero(src_img[..., -1])))
|
| 32 |
+
xyxy[[2, 3]] += xyxy[[0, 1]]
|
| 33 |
+
img = src_img[xyxy[1]: xyxy[3], xyxy[0]: xyxy[2]].copy()
|
| 34 |
+
|
| 35 |
+
save_tmp_img(img, osp.join(saved, imgn + '_input.png'))
|
| 36 |
+
|
| 37 |
+
img_list = []
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
src_infop = osp.join(osp.join(src_dir, 'optimized'), 'info.json')
|
| 41 |
+
infos = json2dict(src_infop)
|
| 42 |
+
load_img_depth(osp.join(src_dir, 'optimized'), infos, pad=0)
|
| 43 |
+
|
| 44 |
+
flist = []
|
| 45 |
+
for k, v in infos['parts'].items():
|
| 46 |
+
# depth_median = v['depth'][v['img'][..., -1] > 127]
|
| 47 |
+
# dm = np.median(depth_median)
|
| 48 |
+
# v['depth_median'] = dm
|
| 49 |
+
if k =='armlf':
|
| 50 |
+
v['depth_median'] = -1.
|
| 51 |
+
if k == 'bottomwear':
|
| 52 |
+
continue
|
| 53 |
+
v.pop('depth')
|
| 54 |
+
save_tmp_img(v['img'])
|
| 55 |
+
flist.append(v)
|
| 56 |
+
|
| 57 |
+
flist.sort(key = lambda x: x['depth_median'], reverse=True)
|
| 58 |
+
# for p in
|
| 59 |
+
|
| 60 |
+
img = img_alpha_blending(
|
| 61 |
+
flist, final_size=sz, premultiplied=False)
|
| 62 |
+
|
| 63 |
+
img = img
|
| 64 |
+
save_tmp_img(img, osp.join(saved, imgn + '_' + heads[ii]) + '.png')
|