Commit
·
d3b2a4b
1
Parent(s):
445b4d2
feat: added disk variant to the space
Browse files- app.py +26 -7
- requirements.txt +3 -2
app.py
CHANGED
|
@@ -11,7 +11,7 @@ import time
|
|
| 11 |
|
| 12 |
|
| 13 |
@spaces.GPU
|
| 14 |
-
def process_images(image1, image2):
|
| 15 |
"""
|
| 16 |
Process two images and return a plot of the matching keypoints.
|
| 17 |
"""
|
|
@@ -19,8 +19,17 @@ def process_images(image1, image2):
|
|
| 19 |
return None
|
| 20 |
|
| 21 |
images = [image1, image2]
|
| 22 |
-
|
| 23 |
-
model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
inputs = processor(images, return_tensors="pt")
|
| 25 |
inputs = inputs.to(model.device)
|
| 26 |
print(
|
|
@@ -148,14 +157,24 @@ with gr.Blocks(title="LightGlue Matching Demo") as demo:
|
|
| 148 |
)
|
| 149 |
gr.Markdown("""
|
| 150 |
## How to use:
|
| 151 |
-
1.
|
| 152 |
-
2.
|
| 153 |
-
3.
|
|
|
|
| 154 |
|
| 155 |
The app will create a side-by-side matching of your images using LightGlue.
|
| 156 |
You can also select an example image pair from the dataset.
|
| 157 |
""")
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
with gr.Row():
|
| 160 |
# Input images on the same row
|
| 161 |
image1 = gr.Image(label="First Image", type="pil")
|
|
@@ -168,7 +187,7 @@ with gr.Blocks(title="LightGlue Matching Demo") as demo:
|
|
| 168 |
output_plot = gr.Plot(label="Matching Results", scale=2)
|
| 169 |
|
| 170 |
# Connect the function
|
| 171 |
-
process_btn.click(fn=process_images, inputs=[image1, image2], outputs=[output_plot])
|
| 172 |
|
| 173 |
# Add some example usage
|
| 174 |
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
@spaces.GPU
|
| 14 |
+
def process_images(image1, image2, detector_choice):
|
| 15 |
"""
|
| 16 |
Process two images and return a plot of the matching keypoints.
|
| 17 |
"""
|
|
|
|
| 19 |
return None
|
| 20 |
|
| 21 |
images = [image1, image2]
|
| 22 |
+
|
| 23 |
+
# Select model based on detector choice
|
| 24 |
+
if detector_choice == "SuperPoint":
|
| 25 |
+
model_name = "ETH-CVG/lightglue_superpoint"
|
| 26 |
+
trust_remote_code = False
|
| 27 |
+
else: # DISK
|
| 28 |
+
model_name = "ETH-CVG/lightglue_disk"
|
| 29 |
+
trust_remote_code = True
|
| 30 |
+
|
| 31 |
+
processor = AutoImageProcessor.from_pretrained(model_name, trust_remote_code=trust_remote_code)
|
| 32 |
+
model = AutoModel.from_pretrained(model_name, device_map="auto", trust_remote_code=trust_remote_code)
|
| 33 |
inputs = processor(images, return_tensors="pt")
|
| 34 |
inputs = inputs.to(model.device)
|
| 35 |
print(
|
|
|
|
| 157 |
)
|
| 158 |
gr.Markdown("""
|
| 159 |
## How to use:
|
| 160 |
+
1. Select a detector (SuperPoint or DISK)
|
| 161 |
+
2. Upload two images using the file uploaders below
|
| 162 |
+
3. Click the 'Match Images' button
|
| 163 |
+
4. View the matched output image below. Higher scores are green, lower scores are red.
|
| 164 |
|
| 165 |
The app will create a side-by-side matching of your images using LightGlue.
|
| 166 |
You can also select an example image pair from the dataset.
|
| 167 |
""")
|
| 168 |
|
| 169 |
+
with gr.Row():
|
| 170 |
+
# Detector choice selector
|
| 171 |
+
detector_choice = gr.Radio(
|
| 172 |
+
choices=["SuperPoint", "DISK"],
|
| 173 |
+
value="SuperPoint",
|
| 174 |
+
label="Detector Choice",
|
| 175 |
+
info="Choose between SuperPoint or DISK detector"
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
with gr.Row():
|
| 179 |
# Input images on the same row
|
| 180 |
image1 = gr.Image(label="First Image", type="pil")
|
|
|
|
| 187 |
output_plot = gr.Plot(label="Matching Results", scale=2)
|
| 188 |
|
| 189 |
# Connect the function
|
| 190 |
+
process_btn.click(fn=process_images, inputs=[image1, image2, detector_choice], outputs=[output_plot])
|
| 191 |
|
| 192 |
# Add some example usage
|
| 193 |
|
requirements.txt
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
gradio>=5.34.2
|
| 2 |
Pillow>=10.0.0
|
| 3 |
numpy>=1.24.0
|
| 4 |
-
transformers @ git+https://github.com/huggingface/transformers.git@
|
| 5 |
matplotlib
|
| 6 |
torch
|
| 7 |
plotly
|
| 8 |
spaces
|
| 9 |
-
accelerate
|
|
|
|
|
|
| 1 |
gradio>=5.34.2
|
| 2 |
Pillow>=10.0.0
|
| 3 |
numpy>=1.24.0
|
| 4 |
+
transformers @ git+https://github.com/huggingface/transformers.git@1255480fd226129075e10c20842efd444f5b0e36
|
| 5 |
matplotlib
|
| 6 |
torch
|
| 7 |
plotly
|
| 8 |
spaces
|
| 9 |
+
accelerate
|
| 10 |
+
kornia
|