Spaces:
Running
Running
gavinyuan
commited on
Commit
·
0ce38bd
1
Parent(s):
4599493
update: PIPNet
Browse files
app.py
CHANGED
|
@@ -188,19 +188,16 @@ def swap_image(
|
|
| 188 |
if gpu_mode:
|
| 189 |
G = G.cuda()
|
| 190 |
|
| 191 |
-
|
| 192 |
-
os.system('ls -hlrt ./third_party/PIPNet/FaceBoxesV2/utils/build')
|
| 193 |
-
os.system('cat ./third_party/PIPNet/FaceBoxesV2/utils/nms/cpu_nms.pyx')
|
| 194 |
-
|
| 195 |
source_img = np.array(Image.open(source_image).convert("RGB"))
|
| 196 |
net, detector = get_lmk_model()
|
| 197 |
-
lmk = get_5_from_98(demo_image(source_img, net, detector)[0])
|
| 198 |
source_img = norm_crop(source_img, lmk, in_size, mode=align_source, borderValue=0.0)
|
| 199 |
source_img = transform(source_img).unsqueeze(0)
|
| 200 |
|
| 201 |
target = np.array(Image.open(target_path).convert("RGB"))
|
| 202 |
original_target = target.copy()
|
| 203 |
-
lmk = get_5_from_98(demo_image(target, net, detector)[0])
|
| 204 |
target, M = norm_crop_with_M(target, lmk, in_size, mode=align_target, borderValue=0.0)
|
| 205 |
target = transform(target).unsqueeze(0)
|
| 206 |
if gpu_mode:
|
|
@@ -238,6 +235,7 @@ def process_video(
|
|
| 238 |
G.eval()
|
| 239 |
if gpu_mode:
|
| 240 |
G = G.cuda()
|
|
|
|
| 241 |
''' Target video to frames (.png) '''
|
| 242 |
fps = 25.0
|
| 243 |
if not os.path.isdir(target_path):
|
|
@@ -265,7 +263,7 @@ def process_video(
|
|
| 265 |
target_lmks = []
|
| 266 |
for frame_path in tqdm.tqdm(globbed_images):
|
| 267 |
target = np.array(Image.open(frame_path).convert("RGB"))
|
| 268 |
-
lmk = demo_image(target, align_net, align_detector)
|
| 269 |
lmk = lmk[0]
|
| 270 |
target_lmks.append(lmk)
|
| 271 |
''' Landmark smoothing '''
|
|
@@ -283,7 +281,7 @@ def process_video(
|
|
| 283 |
''' Crop source image '''
|
| 284 |
source_img = np.array(Image.open(source_image).convert("RGB"))
|
| 285 |
if not use_tddfav2:
|
| 286 |
-
lmk = get_5_from_98(demo_image(source_img, align_net, align_detector)[0])
|
| 287 |
else:
|
| 288 |
lmk = get_lmk(source_img, align_net, align_detector)
|
| 289 |
source_img = norm_crop(source_img, lmk, in_size, mode=align_source, borderValue=0.0)
|
|
|
|
| 188 |
if gpu_mode:
|
| 189 |
G = G.cuda()
|
| 190 |
|
| 191 |
+
device = torch.device(0) if gpu_mode else torch.device('cpu')
|
|
|
|
|
|
|
|
|
|
| 192 |
source_img = np.array(Image.open(source_image).convert("RGB"))
|
| 193 |
net, detector = get_lmk_model()
|
| 194 |
+
lmk = get_5_from_98(demo_image(source_img, net, detector, device=device)[0])
|
| 195 |
source_img = norm_crop(source_img, lmk, in_size, mode=align_source, borderValue=0.0)
|
| 196 |
source_img = transform(source_img).unsqueeze(0)
|
| 197 |
|
| 198 |
target = np.array(Image.open(target_path).convert("RGB"))
|
| 199 |
original_target = target.copy()
|
| 200 |
+
lmk = get_5_from_98(demo_image(target, net, detector, device=device)[0])
|
| 201 |
target, M = norm_crop_with_M(target, lmk, in_size, mode=align_target, borderValue=0.0)
|
| 202 |
target = transform(target).unsqueeze(0)
|
| 203 |
if gpu_mode:
|
|
|
|
| 235 |
G.eval()
|
| 236 |
if gpu_mode:
|
| 237 |
G = G.cuda()
|
| 238 |
+
device = torch.device(0) if gpu_mode else torch.device('cpu')
|
| 239 |
''' Target video to frames (.png) '''
|
| 240 |
fps = 25.0
|
| 241 |
if not os.path.isdir(target_path):
|
|
|
|
| 263 |
target_lmks = []
|
| 264 |
for frame_path in tqdm.tqdm(globbed_images):
|
| 265 |
target = np.array(Image.open(frame_path).convert("RGB"))
|
| 266 |
+
lmk = demo_image(target, align_net, align_detector, device=device)
|
| 267 |
lmk = lmk[0]
|
| 268 |
target_lmks.append(lmk)
|
| 269 |
''' Landmark smoothing '''
|
|
|
|
| 281 |
''' Crop source image '''
|
| 282 |
source_img = np.array(Image.open(source_image).convert("RGB"))
|
| 283 |
if not use_tddfav2:
|
| 284 |
+
lmk = get_5_from_98(demo_image(source_img, align_net, align_detector, device=device)[0])
|
| 285 |
else:
|
| 286 |
lmk = get_lmk(source_img, align_net, align_detector)
|
| 287 |
source_img = norm_crop(source_img, lmk, in_size, mode=align_source, borderValue=0.0)
|