Spaces:
Build error
Build error
Liangyu
commited on
Commit
Β·
0ba37f3
1
Parent(s):
6119602
π 0.1.0 minimum usable app (not deployed)
Browse files- .gitignore +3 -1
- app.py +20 -23
.gitignore
CHANGED
|
@@ -1 +1,3 @@
|
|
| 1 |
-
.vscode
|
|
|
|
|
|
|
|
|
| 1 |
+
.vscode
|
| 2 |
+
*.db
|
| 3 |
+
__pycache__
|
app.py
CHANGED
|
@@ -6,20 +6,18 @@ import argparse
|
|
| 6 |
import os
|
| 7 |
import pathlib
|
| 8 |
import subprocess
|
| 9 |
-
import tarfile
|
| 10 |
|
| 11 |
if os.getenv('SYSTEM') == 'spaces':
|
| 12 |
import mim
|
| 13 |
|
| 14 |
mim.uninstall('mmcv-full', confirm_yes=True)
|
| 15 |
mim.install('mmcv-full==1.5.2', is_yes=True)
|
| 16 |
-
|
| 17 |
-
# mim.install('mmdet==2.20.0', is_yes=True)
|
| 18 |
|
| 19 |
subprocess.call('pip uninstall -y opencv-python'.split())
|
| 20 |
subprocess.call('pip uninstall -y opencv-python-headless'.split())
|
| 21 |
subprocess.call('pip install opencv-python-headless==4.5.5.64'.split())
|
| 22 |
-
subprocess.call('
|
| 23 |
subprocess.call('pip install detectron2==0.5 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.7/index.html'.split())
|
| 24 |
|
| 25 |
import cv2
|
|
@@ -28,9 +26,7 @@ import numpy as np
|
|
| 28 |
|
| 29 |
from mmdet.apis import init_detector, inference_detector
|
| 30 |
from utils import show_result
|
| 31 |
-
import mmcv
|
| 32 |
from mmcv import Config
|
| 33 |
-
import os.path as osp
|
| 34 |
|
| 35 |
DESCRIPTION = '''# OpenPSG
|
| 36 |
|
|
@@ -64,26 +60,29 @@ def update_input_image(image: np.ndarray) -> dict:
|
|
| 64 |
def set_example_image(example: list) -> dict:
|
| 65 |
return gr.Image.update(value=example[0])
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
def infer(
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
|
| 78 |
def main():
|
| 79 |
args = parse_args()
|
| 80 |
|
| 81 |
-
model_ckt ='OpenPSG/checkpoints/epoch_60.pth'
|
| 82 |
-
cfg = Config.fromfile('OpenPSG/configs/psgtr/psgtr_r50_psg_inference.py')
|
| 83 |
-
|
| 84 |
-
model = init_detector(cfg, model_ckt, device=args.device)
|
| 85 |
-
|
| 86 |
with gr.Blocks(theme=args.theme, css='style.css') as demo:
|
|
|
|
|
|
|
|
|
|
| 87 |
gr.Markdown(DESCRIPTION)
|
| 88 |
|
| 89 |
with gr.Row():
|
|
@@ -100,10 +99,8 @@ def main():
|
|
| 100 |
label='Number of Relations')
|
| 101 |
with gr.Row():
|
| 102 |
run_button = gr.Button(value='Run')
|
| 103 |
-
# prediction_results = gr.Variable()
|
| 104 |
with gr.Column():
|
| 105 |
with gr.Row():
|
| 106 |
-
# visualization = gr.Image(label='Result', type='numpy')
|
| 107 |
result = gr.Gallery(label='Result', type='numpy')
|
| 108 |
|
| 109 |
with gr.Row():
|
|
@@ -118,9 +115,9 @@ def main():
|
|
| 118 |
inputs=input_image,
|
| 119 |
outputs=input_image)
|
| 120 |
|
| 121 |
-
run_button.click(fn=infer,
|
| 122 |
inputs=[
|
| 123 |
-
|
| 124 |
],
|
| 125 |
outputs=result)
|
| 126 |
|
|
|
|
| 6 |
import os
|
| 7 |
import pathlib
|
| 8 |
import subprocess
|
|
|
|
| 9 |
|
| 10 |
if os.getenv('SYSTEM') == 'spaces':
|
| 11 |
import mim
|
| 12 |
|
| 13 |
mim.uninstall('mmcv-full', confirm_yes=True)
|
| 14 |
mim.install('mmcv-full==1.5.2', is_yes=True)
|
| 15 |
+
|
|
|
|
| 16 |
|
| 17 |
subprocess.call('pip uninstall -y opencv-python'.split())
|
| 18 |
subprocess.call('pip uninstall -y opencv-python-headless'.split())
|
| 19 |
subprocess.call('pip install opencv-python-headless==4.5.5.64'.split())
|
| 20 |
+
subprocess.call('pip install pycocotools'.split())
|
| 21 |
subprocess.call('pip install detectron2==0.5 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.7/index.html'.split())
|
| 22 |
|
| 23 |
import cv2
|
|
|
|
| 26 |
|
| 27 |
from mmdet.apis import init_detector, inference_detector
|
| 28 |
from utils import show_result
|
|
|
|
| 29 |
from mmcv import Config
|
|
|
|
| 30 |
|
| 31 |
DESCRIPTION = '''# OpenPSG
|
| 32 |
|
|
|
|
| 60 |
def set_example_image(example: list) -> dict:
|
| 61 |
return gr.Image.update(value=example[0])
|
| 62 |
|
| 63 |
+
class Model:
|
| 64 |
+
def __init__(self, model_name, device='cpu'):
|
| 65 |
+
model_ckt ='OpenPSG/checkpoints/epoch_60.pth'
|
| 66 |
+
cfg = Config.fromfile('OpenPSG/configs/psgtr/psgtr_r50_psg_inference.py')
|
| 67 |
+
self.model = init_detector(cfg, model_ckt, device=device)
|
| 68 |
|
| 69 |
+
def infer(self, input_image, num_rel):
|
| 70 |
+
result = inference_detector(self.model, input_image)
|
| 71 |
+
return show_result(input_image,
|
| 72 |
+
result,
|
| 73 |
+
is_one_stage=True,
|
| 74 |
+
num_rel=num_rel,
|
| 75 |
+
show=True
|
| 76 |
+
)
|
| 77 |
|
| 78 |
|
| 79 |
def main():
|
| 80 |
args = parse_args()
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
with gr.Blocks(theme=args.theme, css='style.css') as demo:
|
| 83 |
+
|
| 84 |
+
model = Model('psgtr', device=args.device)
|
| 85 |
+
|
| 86 |
gr.Markdown(DESCRIPTION)
|
| 87 |
|
| 88 |
with gr.Row():
|
|
|
|
| 99 |
label='Number of Relations')
|
| 100 |
with gr.Row():
|
| 101 |
run_button = gr.Button(value='Run')
|
|
|
|
| 102 |
with gr.Column():
|
| 103 |
with gr.Row():
|
|
|
|
| 104 |
result = gr.Gallery(label='Result', type='numpy')
|
| 105 |
|
| 106 |
with gr.Row():
|
|
|
|
| 115 |
inputs=input_image,
|
| 116 |
outputs=input_image)
|
| 117 |
|
| 118 |
+
run_button.click(fn=model.infer,
|
| 119 |
inputs=[
|
| 120 |
+
input_image, num_rel
|
| 121 |
],
|
| 122 |
outputs=result)
|
| 123 |
|