Spaces:
Configuration error
Configuration error
Commit
·
6b70bd5
1
Parent(s):
ac9fa25
brush examples, visualize crop
Browse files- app.py +107 -55
- bad_hands/10_composite.png +3 -0
- bad_hands/11_composite.png +3 -0
- bad_hands/12_composite.png +3 -0
- bad_hands/13_composite.png +3 -0
- bad_hands/1_composite.png +3 -0
- bad_hands/2_composite.png +3 -0
- bad_hands/3_composite.png +3 -0
- bad_hands/4_composite.png +3 -0
- bad_hands/5_composite.png +3 -0
- bad_hands/6_composite.png +3 -0
- bad_hands/7_composite.png +3 -0
- bad_hands/8_composite.png +3 -0
- bad_hands/9_composite.png +3 -0
- debug.png +3 -0
- debug_ex.png +3 -0
- tmp.py +18 -0
app.py
CHANGED
@@ -57,11 +57,9 @@ def remove_prefix(text, prefix):
|
|
57 |
return text[len(prefix) :]
|
58 |
return text
|
59 |
|
60 |
-
|
61 |
def unnormalize(x):
|
62 |
return (((x + 1) / 2) * 255).astype(np.uint8)
|
63 |
|
64 |
-
|
65 |
def visualize_hand(all_joints, img, side=["right", "left"], n_avail_joints=21):
|
66 |
# Define the connections between joints for drawing lines and their corresponding colors
|
67 |
connections = [
|
@@ -127,7 +125,6 @@ def visualize_hand(all_joints, img, side=["right", "left"], n_avail_joints=21):
|
|
127 |
|
128 |
return numpy_img
|
129 |
|
130 |
-
|
131 |
def mask_image(image, mask, color=[0, 0, 0], alpha=0.6, transparent=True):
|
132 |
"""Overlay mask on image for visualization purpose.
|
133 |
Args:
|
@@ -145,7 +142,6 @@ def mask_image(image, mask, color=[0, 0, 0], alpha=0.6, transparent=True):
|
|
145 |
out = img
|
146 |
return out
|
147 |
|
148 |
-
|
149 |
def scale_keypoint(keypoint, original_size, target_size):
|
150 |
"""Scale a keypoint based on the resizing of the image."""
|
151 |
keypoint_copy = keypoint.copy()
|
@@ -153,10 +149,8 @@ def scale_keypoint(keypoint, original_size, target_size):
|
|
153 |
keypoint_copy[:, 1] *= target_size[1] / original_size[1]
|
154 |
return keypoint_copy
|
155 |
|
156 |
-
|
157 |
print("Configure...")
|
158 |
|
159 |
-
|
160 |
@dataclass
|
161 |
class HandDiffOpts:
|
162 |
run_name: str = "ViT_256_handmask_heatmap_nvs_b25_lr1e-5"
|
@@ -451,27 +445,39 @@ def get_target_anno(img, keypts):
|
|
451 |
|
452 |
return img, target_pose, target_cond, keypts, gr.update(), True
|
453 |
|
454 |
-
# def get_mask_inpaint(ref):
|
455 |
-
# # inpaint_mask = np.zeros_like(img_original[:, :, 0])
|
456 |
-
# # cropped_mask = np.array(ref["layers"][0])[..., -1]
|
457 |
-
# # inpaint_mask[crop_coord[0][1]:crop_coord[1][1], crop_coord[0][0]:crop_coord[1][0]] = cropped_mask
|
458 |
-
|
459 |
-
# return inpaint_mask
|
460 |
-
|
461 |
def visualize_ref(ref):
|
462 |
if ref is None:
|
463 |
return None
|
464 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
# inpaint mask
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
|
472 |
# viualization
|
473 |
-
inpainted = ref["layers"][0][..., -1]
|
474 |
-
img = ref["background"][..., :3]
|
475 |
# img = cv2.resize(img, inpainted.shape[::-1], interpolation=cv2.INTER_AREA)
|
476 |
mask = inpainted < 128
|
477 |
# img = img.astype(np.int32)
|
@@ -481,6 +487,15 @@ def visualize_ref(ref):
|
|
481 |
img = mask_image(img, mask)
|
482 |
return img, inpaint_mask
|
483 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
|
485 |
def get_kps(img, keypoints, side: Literal["right", "left"], evt: gr.SelectData):
|
486 |
if keypoints is None:
|
@@ -503,7 +518,6 @@ def get_kps(img, keypoints, side: Literal["right", "left"], evt: gr.SelectData):
|
|
503 |
vis_hand = visualize_hand(kps, img, side, len_kps)
|
504 |
return vis_hand, keypoints
|
505 |
|
506 |
-
|
507 |
def undo_kps(img, keypoints, side: Literal["right", "left"]):
|
508 |
if keypoints is None:
|
509 |
return img, None
|
@@ -523,7 +537,6 @@ def undo_kps(img, keypoints, side: Literal["right", "left"]):
|
|
523 |
vis_hand = visualize_hand(kps, img, side, len_kps)
|
524 |
return vis_hand, keypoints
|
525 |
|
526 |
-
|
527 |
def reset_kps(img, keypoints, side: Literal["right", "left"]):
|
528 |
if keypoints is None:
|
529 |
return img, None
|
@@ -535,29 +548,54 @@ def reset_kps(img, keypoints, side: Literal["right", "left"]):
|
|
535 |
|
536 |
def stay_crop(img, crop_coord):
|
537 |
if img is not None:
|
538 |
-
crop_coord
|
539 |
-
|
540 |
-
|
|
|
|
|
|
|
541 |
else:
|
542 |
return None, None
|
543 |
|
|
|
|
|
|
|
|
|
|
|
|
|
544 |
def process_crop(img, crop_coord, evt:gr.SelectData):
|
545 |
-
|
|
|
546 |
crop_coord = [list(evt.index)]
|
547 |
-
cropped =
|
|
|
|
|
|
|
|
|
548 |
elif len(crop_coord) == 1:
|
549 |
new_coord =list(evt.index)
|
550 |
-
if new_coord[0] <= crop_coord[0][0] or new_coord[1] <= crop_coord[0][1]:
|
551 |
gr.Warning("Second click should be more under and more right thand the first click. Try second click again.", duration=3)
|
552 |
-
cropped =
|
553 |
-
|
|
|
|
|
554 |
crop_coord.append(new_coord)
|
555 |
x1, y1 = crop_coord[0]
|
556 |
x2, y2 = crop_coord[1]
|
557 |
-
cropped =
|
|
|
|
|
|
|
|
|
558 |
else:
|
559 |
gr.Error("Something is wrong", duration=3)
|
560 |
-
|
|
|
|
|
|
|
|
|
|
|
561 |
|
562 |
def disable_crop(crop_coord):
|
563 |
if len(crop_coord) == 2:
|
@@ -749,7 +787,6 @@ def ready_sample(img_cropped, inpaint_mask, keypts):
|
|
749 |
vis_mask256,
|
750 |
)
|
751 |
|
752 |
-
|
753 |
def switch_mask_size(radio):
|
754 |
if radio == "256x256":
|
755 |
out = (gr.update(visible=False), gr.update(visible=True))
|
@@ -829,7 +866,6 @@ def sample_inpaint(
|
|
829 |
results_original.append(placeholder)
|
830 |
return results, results_pose, results_original
|
831 |
|
832 |
-
|
833 |
def flip_hand(
|
834 |
img, img_raw, pose_img, pose_manual_img,
|
835 |
manual_kp_right, manual_kp_left,
|
@@ -884,14 +920,12 @@ def flip_hand(
|
|
884 |
manual_keypts[21:, 0] = opts.image_size[1] - manual_keypts[21:, 0]
|
885 |
return img, img_raw, pose_img, pose_manual_img, manual_kp_right, manual_kp_left, cond, auto_cond, manual_cond, keypts, auto_keypts, manual_keypts
|
886 |
|
887 |
-
|
888 |
def resize_to_full(img):
|
889 |
img["background"] = cv2.resize(img["background"], (LENGTH, LENGTH))
|
890 |
img["composite"] = cv2.resize(img["composite"], (LENGTH, LENGTH))
|
891 |
img["layers"] = [cv2.resize(layer, (LENGTH, LENGTH)) for layer in img["layers"]]
|
892 |
return img
|
893 |
|
894 |
-
|
895 |
def clear_all():
|
896 |
return (
|
897 |
None,
|
@@ -921,7 +955,6 @@ def clear_all():
|
|
921 |
gr.update(interactive=False),
|
922 |
)
|
923 |
|
924 |
-
|
925 |
def fix_clear_all():
|
926 |
return (
|
927 |
None,
|
@@ -951,7 +984,6 @@ def fix_clear_all():
|
|
951 |
10,
|
952 |
)
|
953 |
|
954 |
-
|
955 |
def enable_component(image1, image2):
|
956 |
if image1 is None or image2 is None:
|
957 |
return gr.update(interactive=False)
|
@@ -971,7 +1003,6 @@ def enable_component(image1, image2):
|
|
971 |
return gr.update(interactive=False)
|
972 |
return gr.update(interactive=True)
|
973 |
|
974 |
-
|
975 |
def set_visible(checkbox, kpts, img_clean, img_pose_right, img_pose_left, done=None, done_info=None):
|
976 |
if kpts is None:
|
977 |
kpts = [[], []]
|
@@ -1162,18 +1193,28 @@ fix_example_imgs = [
|
|
1162 |
["bad_hands/1.jpg"], # "bad_hands/1_mask.jpg"],
|
1163 |
# ["bad_hands/2.jpg"], # "bad_hands/2_mask.jpg"],
|
1164 |
["bad_hands/3.jpg"], # "bad_hands/3_mask.jpg"],
|
1165 |
-
|
1166 |
["bad_hands/5.jpg"], # "bad_hands/5_mask.jpg"],
|
1167 |
["bad_hands/6.jpg"], # "bad_hands/6_mask.jpg"],
|
1168 |
-
|
1169 |
# ["bad_hands/8.jpg"], # "bad_hands/8_mask.jpg"],
|
1170 |
# ["bad_hands/9.jpg"], # "bad_hands/9_mask.jpg"],
|
1171 |
# ["bad_hands/10.jpg"], # "bad_hands/10_mask.jpg"],
|
1172 |
# ["bad_hands/11.jpg"], # "bad_hands/11_mask.jpg"],
|
1173 |
# ["bad_hands/12.jpg"], # "bad_hands/12_mask.jpg"],
|
1174 |
# ["bad_hands/13.jpg"], # "bad_hands/13_mask.jpg"],
|
1175 |
-
["bad_hands/14.jpg"],
|
1176 |
-
["bad_hands/15.jpg"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1177 |
]
|
1178 |
custom_css = """
|
1179 |
.gradio-container .examples img {
|
@@ -1286,6 +1327,7 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1286 |
width=LENGTH,
|
1287 |
interactive=True,
|
1288 |
visible=True,
|
|
|
1289 |
)
|
1290 |
gr.Markdown(
|
1291 |
"""<p style="text-align: center;">💡 If you crop, the model can focus on more details of the cropped area. Square crops might work better than rectangle crops.</p>"""
|
@@ -1304,6 +1346,8 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1304 |
fix_example_imgs,
|
1305 |
inputs=[fix_crop],
|
1306 |
examples_per_page=20,
|
|
|
|
|
1307 |
)
|
1308 |
with gr.Column():
|
1309 |
gr.Markdown(
|
@@ -1326,14 +1370,22 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1326 |
), # 204, 50, 50
|
1327 |
image_mode="RGBA",
|
1328 |
container=False,
|
1329 |
-
interactive=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1330 |
)
|
1331 |
# gr.Markdown(
|
1332 |
# """<p style="text-align: center;">③ Hit the \"Finish Cropping & Brushing\" button</p>"""
|
1333 |
# )
|
1334 |
-
fix_finish_crop = gr.Button(
|
1335 |
-
|
1336 |
-
)
|
1337 |
|
1338 |
# keypoint selection
|
1339 |
with gr.Column():
|
@@ -1526,18 +1578,18 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
1526 |
|
1527 |
# listeners
|
1528 |
# fix_crop.change(resize_to_full, fix_crop, fix_ref)
|
1529 |
-
fix_crop.change(
|
1530 |
fix_crop.change(stay_crop, [fix_crop, fix_crop_coord], [fix_crop_coord, fix_ref])
|
1531 |
-
fix_crop.select(process_crop, [fix_crop, fix_crop_coord], [fix_crop_coord, fix_ref])
|
1532 |
# fix_ref.change(disable_crop, fix_crop_coord, fix_crop)
|
1533 |
-
fix_ref.change(enable_component, [fix_crop, fix_crop], fix_ref)
|
1534 |
-
fix_ref.change(enable_component, [fix_crop, fix_crop], fix_finish_crop)
|
1535 |
-
|
1536 |
# fix_finish_crop.click(get_mask_inpaint, [fix_ref], []) # fix_ref: (real_cropped_H, real_cropped_W, 3)
|
1537 |
fix_img.change(lambda x: x, [fix_img], [fix_kp_right])
|
1538 |
fix_img.change(lambda x: x, [fix_img], [fix_kp_left])
|
1539 |
-
|
1540 |
-
enable_component, [
|
1541 |
)
|
1542 |
fix_inpaint_mask.change(
|
1543 |
enable_component, [fix_inpaint_mask, fix_inpaint_mask], fix_kp_right
|
@@ -2220,7 +2272,7 @@ with gr.Blocks(css=custom_css, theme="soft") as demo:
|
|
2220 |
gr.Markdown("<h1>Acknowledgement</h1>")
|
2221 |
gr.Markdown(_ACK_)
|
2222 |
gr.Markdown("<h1>Trouble Shooting</h1>")
|
2223 |
-
gr.Markdown("If something doesn't work,
|
2224 |
gr.Markdown("<h1>Citation</h1>")
|
2225 |
gr.Markdown(
|
2226 |
"""<p style="text-align: left;">If this was useful, please cite us! ❤️</p>"""
|
|
|
57 |
return text[len(prefix) :]
|
58 |
return text
|
59 |
|
|
|
60 |
def unnormalize(x):
|
61 |
return (((x + 1) / 2) * 255).astype(np.uint8)
|
62 |
|
|
|
63 |
def visualize_hand(all_joints, img, side=["right", "left"], n_avail_joints=21):
|
64 |
# Define the connections between joints for drawing lines and their corresponding colors
|
65 |
connections = [
|
|
|
125 |
|
126 |
return numpy_img
|
127 |
|
|
|
128 |
def mask_image(image, mask, color=[0, 0, 0], alpha=0.6, transparent=True):
|
129 |
"""Overlay mask on image for visualization purpose.
|
130 |
Args:
|
|
|
142 |
out = img
|
143 |
return out
|
144 |
|
|
|
145 |
def scale_keypoint(keypoint, original_size, target_size):
|
146 |
"""Scale a keypoint based on the resizing of the image."""
|
147 |
keypoint_copy = keypoint.copy()
|
|
|
149 |
keypoint_copy[:, 1] *= target_size[1] / original_size[1]
|
150 |
return keypoint_copy
|
151 |
|
|
|
152 |
print("Configure...")
|
153 |
|
|
|
154 |
@dataclass
|
155 |
class HandDiffOpts:
|
156 |
run_name: str = "ViT_256_handmask_heatmap_nvs_b25_lr1e-5"
|
|
|
445 |
|
446 |
return img, target_pose, target_cond, keypts, gr.update(), True
|
447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
def visualize_ref(ref):
|
449 |
if ref is None:
|
450 |
return None
|
451 |
|
452 |
+
# from user or from example
|
453 |
+
h, w = ref["background"].shape[:2]
|
454 |
+
if ref["layers"][0].sum() == 0:
|
455 |
+
if ref["background"][:, :, -1].sum() == h * w * 255:
|
456 |
+
from_example = False
|
457 |
+
else:
|
458 |
+
from_example = True
|
459 |
+
else:
|
460 |
+
from_example = False
|
461 |
+
|
462 |
# inpaint mask
|
463 |
+
if from_example:
|
464 |
+
inpaint_mask = ref["background"][:, :, -1]
|
465 |
+
inpainted = inpaint_mask.copy()
|
466 |
+
inpaint_mask = cv2.resize(
|
467 |
+
inpaint_mask, opts.image_size, interpolation=cv2.INTER_AREA
|
468 |
+
)
|
469 |
+
inpaint_mask = (inpaint_mask > 128).astype(np.uint8)
|
470 |
+
img = cv2.cvtColor(ref["background"], cv2.COLOR_RGBA2RGB)
|
471 |
+
else:
|
472 |
+
inpaint_mask = np.array(ref["layers"][0])[..., -1]
|
473 |
+
inpaint_mask = cv2.resize(
|
474 |
+
inpaint_mask, opts.image_size, interpolation=cv2.INTER_AREA
|
475 |
+
)
|
476 |
+
inpaint_mask = (inpaint_mask >= 128).astype(np.uint8)
|
477 |
+
inpainted = ref["layers"][0][..., -1]
|
478 |
+
img = ref["background"][..., :3]
|
479 |
|
480 |
# viualization
|
|
|
|
|
481 |
# img = cv2.resize(img, inpainted.shape[::-1], interpolation=cv2.INTER_AREA)
|
482 |
mask = inpainted < 128
|
483 |
# img = img.astype(np.int32)
|
|
|
487 |
img = mask_image(img, mask)
|
488 |
return img, inpaint_mask
|
489 |
|
490 |
+
# def inpaint_from_example(ex_mask):
|
491 |
+
# inpaint_mask = (ex_mask[:,:, -1] == 0).astype(np.uint8)
|
492 |
+
# inpaint_mask = np.tile(inpaint_mask[..., None], (1, 1, 4))
|
493 |
+
# ret = {
|
494 |
+
# "background": cv2.cvtColor(ex_mask, cv2.COLOR_RGB2RGBA),
|
495 |
+
# "layers": [inpaint_mask],
|
496 |
+
# "composite": cv2.cvtColor(ex_mask, cv2.COLOR_RGB2RGBA)
|
497 |
+
# }
|
498 |
+
# return ret
|
499 |
|
500 |
def get_kps(img, keypoints, side: Literal["right", "left"], evt: gr.SelectData):
|
501 |
if keypoints is None:
|
|
|
518 |
vis_hand = visualize_hand(kps, img, side, len_kps)
|
519 |
return vis_hand, keypoints
|
520 |
|
|
|
521 |
def undo_kps(img, keypoints, side: Literal["right", "left"]):
|
522 |
if keypoints is None:
|
523 |
return img, None
|
|
|
537 |
vis_hand = visualize_hand(kps, img, side, len_kps)
|
538 |
return vis_hand, keypoints
|
539 |
|
|
|
540 |
def reset_kps(img, keypoints, side: Literal["right", "left"]):
|
541 |
if keypoints is None:
|
542 |
return img, None
|
|
|
548 |
|
549 |
def stay_crop(img, crop_coord):
|
550 |
if img is not None:
|
551 |
+
if crop_coord is None:
|
552 |
+
crop_coord = [[0, 0], [img.shape[1], img.shape[0]]]
|
553 |
+
cropped = img.copy()
|
554 |
+
return crop_coord, cropped
|
555 |
+
else:
|
556 |
+
return gr.update(), gr.update()
|
557 |
else:
|
558 |
return None, None
|
559 |
|
560 |
+
def stash_original(img):
|
561 |
+
if img is None:
|
562 |
+
return None
|
563 |
+
else:
|
564 |
+
return img[:,:,:3]
|
565 |
+
|
566 |
def process_crop(img, crop_coord, evt:gr.SelectData):
|
567 |
+
image = img.copy()
|
568 |
+
if len(crop_coord) == 2: # will add first click
|
569 |
crop_coord = [list(evt.index)]
|
570 |
+
cropped = image
|
571 |
+
cropped_vis = image.copy()
|
572 |
+
alpha = np.ones_like(cropped_vis[:,:, -1]) * 255
|
573 |
+
cv2.circle(alpha, tuple(crop_coord[0]), 5, 0, 4)
|
574 |
+
cropped_vis[:,:,-1] = alpha
|
575 |
elif len(crop_coord) == 1:
|
576 |
new_coord =list(evt.index)
|
577 |
+
if new_coord[0] <= crop_coord[0][0] or new_coord[1] <= crop_coord[0][1]: # will skip
|
578 |
gr.Warning("Second click should be more under and more right thand the first click. Try second click again.", duration=3)
|
579 |
+
cropped = image
|
580 |
+
cropped_vis = image.copy()
|
581 |
+
cropped_vis[:,:,-1] = 255
|
582 |
+
else: # will add second click
|
583 |
crop_coord.append(new_coord)
|
584 |
x1, y1 = crop_coord[0]
|
585 |
x2, y2 = crop_coord[1]
|
586 |
+
cropped = image[y1:y2, x1:x2]
|
587 |
+
cropped_vis = image.copy()
|
588 |
+
alpha = np.ones_like(cropped_vis[:,:, -1]) * 255
|
589 |
+
cv2.rectangle(alpha, tuple([x1, y1]), tuple([x2, y2]), 0, 4)
|
590 |
+
cropped_vis[:,:,-1] = alpha
|
591 |
else:
|
592 |
gr.Error("Something is wrong", duration=3)
|
593 |
+
# cropped_editor = {
|
594 |
+
# "background": cropped,
|
595 |
+
# "composite": cropped,
|
596 |
+
# "layers": [cropped_vis]
|
597 |
+
# }
|
598 |
+
return crop_coord, cropped, cropped_vis
|
599 |
|
600 |
def disable_crop(crop_coord):
|
601 |
if len(crop_coord) == 2:
|
|
|
787 |
vis_mask256,
|
788 |
)
|
789 |
|
|
|
790 |
def switch_mask_size(radio):
|
791 |
if radio == "256x256":
|
792 |
out = (gr.update(visible=False), gr.update(visible=True))
|
|
|
866 |
results_original.append(placeholder)
|
867 |
return results, results_pose, results_original
|
868 |
|
|
|
869 |
def flip_hand(
|
870 |
img, img_raw, pose_img, pose_manual_img,
|
871 |
manual_kp_right, manual_kp_left,
|
|
|
920 |
manual_keypts[21:, 0] = opts.image_size[1] - manual_keypts[21:, 0]
|
921 |
return img, img_raw, pose_img, pose_manual_img, manual_kp_right, manual_kp_left, cond, auto_cond, manual_cond, keypts, auto_keypts, manual_keypts
|
922 |
|
|
|
923 |
def resize_to_full(img):
|
924 |
img["background"] = cv2.resize(img["background"], (LENGTH, LENGTH))
|
925 |
img["composite"] = cv2.resize(img["composite"], (LENGTH, LENGTH))
|
926 |
img["layers"] = [cv2.resize(layer, (LENGTH, LENGTH)) for layer in img["layers"]]
|
927 |
return img
|
928 |
|
|
|
929 |
def clear_all():
|
930 |
return (
|
931 |
None,
|
|
|
955 |
gr.update(interactive=False),
|
956 |
)
|
957 |
|
|
|
958 |
def fix_clear_all():
|
959 |
return (
|
960 |
None,
|
|
|
984 |
10,
|
985 |
)
|
986 |
|
|
|
987 |
def enable_component(image1, image2):
|
988 |
if image1 is None or image2 is None:
|
989 |
return gr.update(interactive=False)
|
|
|
1003 |
return gr.update(interactive=False)
|
1004 |
return gr.update(interactive=True)
|
1005 |
|
|
|
1006 |
def set_visible(checkbox, kpts, img_clean, img_pose_right, img_pose_left, done=None, done_info=None):
|
1007 |
if kpts is None:
|
1008 |
kpts = [[], []]
|
|
|
1193 |
["bad_hands/1.jpg"], # "bad_hands/1_mask.jpg"],
|
1194 |
# ["bad_hands/2.jpg"], # "bad_hands/2_mask.jpg"],
|
1195 |
["bad_hands/3.jpg"], # "bad_hands/3_mask.jpg"],
|
1196 |
+
["bad_hands/4.jpg"], # "bad_hands/4_mask.jpg"],
|
1197 |
["bad_hands/5.jpg"], # "bad_hands/5_mask.jpg"],
|
1198 |
["bad_hands/6.jpg"], # "bad_hands/6_mask.jpg"],
|
1199 |
+
["bad_hands/7.jpg"], # "bad_hands/7_mask.jpg"],
|
1200 |
# ["bad_hands/8.jpg"], # "bad_hands/8_mask.jpg"],
|
1201 |
# ["bad_hands/9.jpg"], # "bad_hands/9_mask.jpg"],
|
1202 |
# ["bad_hands/10.jpg"], # "bad_hands/10_mask.jpg"],
|
1203 |
# ["bad_hands/11.jpg"], # "bad_hands/11_mask.jpg"],
|
1204 |
# ["bad_hands/12.jpg"], # "bad_hands/12_mask.jpg"],
|
1205 |
# ["bad_hands/13.jpg"], # "bad_hands/13_mask.jpg"],
|
1206 |
+
# ["bad_hands/14.jpg"],
|
1207 |
+
# ["bad_hands/15.jpg"],
|
1208 |
+
]
|
1209 |
+
fix_example_brush = [
|
1210 |
+
["bad_hands/1_composite.png"],# "bad_hands/1.jpg"],
|
1211 |
+
["bad_hands/3_composite.png"],# "bad_hands/3.jpg"],
|
1212 |
+
["bad_hands/4_composite.png"],# "bad_hands/4.jpg"],
|
1213 |
+
["bad_hands/5_composite.png"],# "bad_hands/5.jpg"],
|
1214 |
+
["bad_hands/6_composite.png"],# "bad_hands/6.jpg"],
|
1215 |
+
["bad_hands/7_composite.png"],# "bad_hands/7.jpg"],
|
1216 |
+
# ["bad_hands/14_mask.jpg"],
|
1217 |
+
# ["bad_hands/15_mask.jpg"],
|
1218 |
]
|
1219 |
custom_css = """
|
1220 |
.gradio-container .examples img {
|
|
|
1327 |
width=LENGTH,
|
1328 |
interactive=True,
|
1329 |
visible=True,
|
1330 |
+
image_mode="RGBA"
|
1331 |
)
|
1332 |
gr.Markdown(
|
1333 |
"""<p style="text-align: center;">💡 If you crop, the model can focus on more details of the cropped area. Square crops might work better than rectangle crops.</p>"""
|
|
|
1346 |
fix_example_imgs,
|
1347 |
inputs=[fix_crop],
|
1348 |
examples_per_page=20,
|
1349 |
+
# run_on_click=True,
|
1350 |
+
# fn=load_brush,
|
1351 |
)
|
1352 |
with gr.Column():
|
1353 |
gr.Markdown(
|
|
|
1370 |
), # 204, 50, 50
|
1371 |
image_mode="RGBA",
|
1372 |
container=False,
|
1373 |
+
interactive=True,
|
1374 |
+
)
|
1375 |
+
fix_ex_brush = gr.Examples(
|
1376 |
+
fix_example_brush,
|
1377 |
+
inputs=[fix_ref],
|
1378 |
+
# outputs=[fix_ref],
|
1379 |
+
examples_per_page=20,
|
1380 |
+
# run_on_click=True,
|
1381 |
+
# fn=inpaint_from_example,
|
1382 |
)
|
1383 |
# gr.Markdown(
|
1384 |
# """<p style="text-align: center;">③ Hit the \"Finish Cropping & Brushing\" button</p>"""
|
1385 |
# )
|
1386 |
+
# fix_finish_crop = gr.Button(
|
1387 |
+
# value="Finish Croping & Brushing", interactive=False
|
1388 |
+
# )
|
1389 |
|
1390 |
# keypoint selection
|
1391 |
with gr.Column():
|
|
|
1578 |
|
1579 |
# listeners
|
1580 |
# fix_crop.change(resize_to_full, fix_crop, fix_ref)
|
1581 |
+
fix_crop.change(stash_original, fix_crop, fix_original) # fix_original: (real_H, real_W, 3)
|
1582 |
fix_crop.change(stay_crop, [fix_crop, fix_crop_coord], [fix_crop_coord, fix_ref])
|
1583 |
+
fix_crop.select(process_crop, [fix_crop, fix_crop_coord], [fix_crop_coord, fix_ref, fix_crop])
|
1584 |
# fix_ref.change(disable_crop, fix_crop_coord, fix_crop)
|
1585 |
+
# fix_ref.change(enable_component, [fix_crop, fix_crop], fix_ref)
|
1586 |
+
# fix_ref.change(enable_component, [fix_crop, fix_crop], fix_finish_crop)
|
1587 |
+
fix_ref.change(visualize_ref, [fix_ref], [fix_img, fix_inpaint_mask])
|
1588 |
# fix_finish_crop.click(get_mask_inpaint, [fix_ref], []) # fix_ref: (real_cropped_H, real_cropped_W, 3)
|
1589 |
fix_img.change(lambda x: x, [fix_img], [fix_kp_right])
|
1590 |
fix_img.change(lambda x: x, [fix_img], [fix_kp_left])
|
1591 |
+
fix_ref.change(
|
1592 |
+
enable_component, [fix_ref, fix_ref], fix_checkbox
|
1593 |
)
|
1594 |
fix_inpaint_mask.change(
|
1595 |
enable_component, [fix_inpaint_mask, fix_inpaint_mask], fix_kp_right
|
|
|
2272 |
gr.Markdown("<h1>Acknowledgement</h1>")
|
2273 |
gr.Markdown(_ACK_)
|
2274 |
gr.Markdown("<h1>Trouble Shooting</h1>")
|
2275 |
+
gr.Markdown("If something doesn't work, please try the following steps:<br>1. Refresh the page and try again.<br>2. If the issue persists, kindly leave a message on our HuggingFace Spaces Community tab (located at the top right), on our GitHub repository's Issues page, or send us an email. We are happy to help you as soon as possible.<br>3. The issue might be due to compatibility with HuggingFace or GPU VRAM limitations. We recommend cloning this repository and trying it with your own GPU if possible.")
|
2276 |
gr.Markdown("<h1>Citation</h1>")
|
2277 |
gr.Markdown(
|
2278 |
"""<p style="text-align: left;">If this was useful, please cite us! ❤️</p>"""
|
bad_hands/10_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/11_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/12_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/13_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/1_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/2_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/3_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/4_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/5_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/6_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/7_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/8_composite.png
ADDED
![]() |
Git LFS Details
|
bad_hands/9_composite.png
ADDED
![]() |
Git LFS Details
|
debug.png
ADDED
![]() |
Git LFS Details
|
debug_ex.png
ADDED
![]() |
Git LFS Details
|
tmp.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import glob
|
2 |
+
import os
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
img_dir = "bad_hands"
|
7 |
+
masked_paths = sorted(glob.glob(os.path.join(img_dir, "*_mask.jpg")))
|
8 |
+
for masked_pth in masked_paths:
|
9 |
+
img_path = masked_pth.replace("_mask.jpg", ".jpg")
|
10 |
+
assert os.path.exists(img_path), f"Image path {img_path} does not exist."
|
11 |
+
masked = np.array(Image.open(masked_pth))
|
12 |
+
mask = (np.all(masked > 245, axis=-1)).astype(np.uint8)*128 + 64
|
13 |
+
img = np.array(Image.open(img_path))
|
14 |
+
composite = np.concatenate((img, mask[..., None]), axis=-1)
|
15 |
+
# img.putalpha(Image.fromarray(mask))
|
16 |
+
composite = Image.fromarray(composite)
|
17 |
+
composite.save(masked_pth.replace("_mask.jpg", "_composite.png"))
|
18 |
+
print(f"Saved composite image {masked_pth.replace('_mask.jpg', '_composite.png')}")
|