Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,35 @@
|
|
| 1 |
import os
|
| 2 |
os.system("pip install git+https://github.com/facebookresearch/detectron2.git")
|
| 3 |
-
os.system("
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
if __name__ == "__main__":
|
| 8 |
gr.close_all()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def inference(img, confidence):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# img = np.array(img)
|
| 14 |
-
# _, results = vis_demo.run_on_image(img, confidence)
|
| 15 |
return results
|
| 16 |
|
| 17 |
demo = gr.Interface(
|
|
@@ -21,9 +39,9 @@ if __name__ == "__main__":
|
|
| 21 |
gr.Number(precision=2, minimum=0.0, maximum=1.0, value=0.5)
|
| 22 |
],
|
| 23 |
outputs="image",
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
)
|
| 29 |
-
demo.launch(
|
|
|
|
| 1 |
import os
|
| 2 |
os.system("pip install git+https://github.com/facebookresearch/detectron2.git")
|
| 3 |
+
os.system("git clone https://github.com/Visual-AI/Mr.DETR.git")
|
| 4 |
+
os.system("cd Mr.DETR")
|
| 5 |
+
os.system("pip install . && cd ..")
|
| 6 |
+
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
+
from demo.predictors import VisualizationDemo
|
| 10 |
+
from detectron2.checkpoint import DetectionCheckpointer
|
| 11 |
+
from detectron2.config import LazyConfig, instantiate
|
| 12 |
+
import numpy as np
|
| 13 |
|
| 14 |
if __name__ == "__main__":
|
| 15 |
gr.close_all()
|
| 16 |
+
cfg = LazyConfig.load("Mr.DETR/projects/mr_detr_align/configs/deformable_detr_swinl_two_stage_12ep_plusplus.py")
|
| 17 |
+
model = instantiate(cfg.model)
|
| 18 |
+
checkpointer = DetectionCheckpointer(model)
|
| 19 |
+
checkpointer.load("https://huggingface.co/allencbzhang/Mr.DETR/blob/main/MrDETR_align_swinL_12ep_900q.pth")
|
| 20 |
+
|
| 21 |
+
model.eval()
|
| 22 |
+
vis_demo = VisualizationDemo(
|
| 23 |
+
model=model,
|
| 24 |
+
min_size_test=800,
|
| 25 |
+
max_size_test=1333,
|
| 26 |
+
img_format="RGB",
|
| 27 |
+
metadata_dataset="coco_2017_val",
|
| 28 |
+
)
|
| 29 |
|
| 30 |
def inference(img, confidence):
|
| 31 |
+
img = np.array(img)
|
| 32 |
+
_, results = vis_demo.run_on_image(img, confidence)
|
|
|
|
|
|
|
| 33 |
return results
|
| 34 |
|
| 35 |
demo = gr.Interface(
|
|
|
|
| 39 |
gr.Number(precision=2, minimum=0.0, maximum=1.0, value=0.5)
|
| 40 |
],
|
| 41 |
outputs="image",
|
| 42 |
+
examples=[
|
| 43 |
+
["Mr.DETR/assets/000000014226.jpg"],
|
| 44 |
+
["Mr.DETR/assets/000000028449.jpg"]
|
| 45 |
+
]
|
| 46 |
)
|
| 47 |
+
demo.launch()
|