Spaces:
Running
on
Zero
Running
on
Zero
File size: 5,853 Bytes
e79ef02 9c4cd96 184241a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
import os
import mim
mim.install('mmcv-full==1.7.2')
mim.install('mmdet==2.28.2')
mim.install('mmpose==0.29.0')
import argparse
from pathlib import Path
import gradio as gr
import matplotlib
from gradio_utils.utils import (process_img, get_select_coords, select_skeleton,
reset_skeleton, reset_kp, process)
LENGTH = 480 # Length of the square area displaying/editing images
matplotlib.use('agg')
model_dir = Path('./checkpoints')
parser = argparse.ArgumentParser(description='EdgeCape Demo')
parser.add_argument('--checkpoint',
help='checkpoint path',
default='ckpt/1shot_split1.pth')
args = parser.parse_args()
checkpoint_path = args.checkpoint
device = 'cuda'
TIMEOUT = 80
with gr.Blocks() as demo:
gr.Markdown('''
# We introduce EdgeCape, a novel framework that overcomes these limitations by predicting the graph's edge weights which optimizes localization.
To further leverage structural priors, we propose integrating Markovian Structural Bias, which modulates the self-attention interaction between nodes based on the number of hops between them.
We show that this improves the model’s ability to capture global spatial dependencies.
Evaluated on the MP-100 benchmark, which includes 100 categories and over 20K images,
EdgeCape achieves state-of-the-art results in the 1-shot setting and leads among similar-sized methods in the 5-shot setting, significantly improving keypoint localization accuracy.
### [Paper](https://arxiv.org/pdf/2411.16665) | [Project Page](https://orhir.github.io/edge_cape/)
## Instructions
1. Upload an image of the object you want to pose.
2. Mark keypoints on the image.
3. Mark limbs on the image.
4. Upload an image of the object you want to pose to the query image (**bottom**).
5. Click **Evaluate** to pose the query image.
''')
global_state = gr.State({
"images": {},
"points": [],
"skeleton": [],
"prev_point": None,
"curr_type_point": "start",
})
with gr.Row():
# Upload & Preprocess Image Column
with gr.Column():
gr.Markdown(
"""<p style="text-align: center; font-size: 20px">Upload & Preprocess Image</p>"""
)
support_image = gr.Image(
height=LENGTH,
width=LENGTH,
type="pil",
image_mode="RGB",
label="Preprocess Image",
show_label=True,
interactive=True,
)
# Click Points Column
with gr.Column():
gr.Markdown(
"""<p style="text-align: center; font-size: 20px">Click Points</p>"""
)
kp_support_image = gr.Image(
type="pil",
label="Keypoints Image",
show_label=True,
height=LENGTH,
width=LENGTH,
interactive=False,
show_fullscreen_button=False,
)
with gr.Row():
confirm_kp_button = gr.Button("Confirm Clicked Points", scale=3)
with gr.Row():
undo_kp_button = gr.Button("Undo Clicked Points", scale=3)
# Editing Results Column
with gr.Column():
gr.Markdown(
"""<p style="text-align: center; font-size: 20px">Click Skeleton</p>"""
)
skel_support_image = gr.Image(
type="pil",
label="Skeleton Image",
show_label=True,
height=LENGTH,
width=LENGTH,
interactive=False,
show_fullscreen_button=False,
)
with gr.Row():
pass
with gr.Row():
undo_skel_button = gr.Button("Undo Skeleton")
with gr.Row():
with gr.Column():
gr.Markdown(
"""<p style="text-align: center; font-size: 20px">Query Image</p>"""
)
query_image = gr.Image(
type="pil",
image_mode="RGB",
label="Query Image",
show_label=True,
interactive=True,
)
with gr.Column():
gr.Markdown(
"""<p style="text-align: center; font-size: 20px">Output</p>"""
)
output_img = gr.Plot(label="Output Image",)
with gr.Row():
eval_btn = gr.Button(value="Evaluate")
with gr.Row():
gr.Markdown("## Examples")
support_image.change(process_img,
inputs=[support_image, global_state],
outputs=[kp_support_image, global_state])
kp_support_image.select(get_select_coords,
[global_state],
[global_state, kp_support_image],
queue=False,)
confirm_kp_button.click(reset_skeleton,
inputs=global_state,
outputs=skel_support_image)
undo_kp_button.click(reset_kp,
inputs=global_state,
outputs=[kp_support_image, skel_support_image])
undo_skel_button.click(reset_skeleton,
inputs=global_state,
outputs=skel_support_image)
skel_support_image.select(select_skeleton,
inputs=[global_state],
outputs=[global_state, skel_support_image])
eval_btn.click(fn=process,
inputs=[query_image, global_state],
outputs=[output_img, global_state])
if __name__ == "__main__":
print("Start app", parser.parse_args())
gr.close_all()
demo.launch(show_api=False)
|