Spaces:
Runtime error
Runtime error
Limit input image size to avoid out of memory error
Browse files
app.py
CHANGED
|
@@ -18,7 +18,9 @@ if os.getenv('SYSTEM') == 'spaces':
|
|
| 18 |
subprocess.call('pip uninstall -y opencv-python-headless'.split())
|
| 19 |
subprocess.call('pip install opencv-python-headless'.split())
|
| 20 |
|
|
|
|
| 21 |
import gradio as gr
|
|
|
|
| 22 |
|
| 23 |
from model import Model
|
| 24 |
|
|
@@ -50,6 +52,15 @@ def extract_tar() -> None:
|
|
| 50 |
f.extractall('mmdet_configs')
|
| 51 |
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
def update_model_name(model_type: str) -> dict:
|
| 54 |
model_dict = getattr(Model, f'{model_type.upper()}_MODEL_DICT')
|
| 55 |
model_names = list(model_dict.keys())
|
|
@@ -132,6 +143,10 @@ This is an unofficial demo for [https://github.com/open-mmlab/mmdetection](https
|
|
| 132 |
'<center><img src="https://visitor-badge.glitch.me/badge?page_id=hysts.mmdetection" alt="visitor badge"/></center>'
|
| 133 |
)
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
model_type.change(fn=update_model_name,
|
| 136 |
inputs=[model_type],
|
| 137 |
outputs=[model_name])
|
|
|
|
| 18 |
subprocess.call('pip uninstall -y opencv-python-headless'.split())
|
| 19 |
subprocess.call('pip install opencv-python-headless'.split())
|
| 20 |
|
| 21 |
+
import cv2
|
| 22 |
import gradio as gr
|
| 23 |
+
import numpy as np
|
| 24 |
|
| 25 |
from model import Model
|
| 26 |
|
|
|
|
| 52 |
f.extractall('mmdet_configs')
|
| 53 |
|
| 54 |
|
| 55 |
+
def update_input_image(image: np.ndarray) -> dict:
|
| 56 |
+
if image is None:
|
| 57 |
+
return gr.Image.update(value=None)
|
| 58 |
+
scale = 1500 / max(image.shape[:2])
|
| 59 |
+
if scale < 1:
|
| 60 |
+
image = cv2.resize(image, None, fx=scale, fy=scale)
|
| 61 |
+
return gr.Image.update(value=image)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
def update_model_name(model_type: str) -> dict:
|
| 65 |
model_dict = getattr(Model, f'{model_type.upper()}_MODEL_DICT')
|
| 66 |
model_names = list(model_dict.keys())
|
|
|
|
| 143 |
'<center><img src="https://visitor-badge.glitch.me/badge?page_id=hysts.mmdetection" alt="visitor badge"/></center>'
|
| 144 |
)
|
| 145 |
|
| 146 |
+
input_image.change(fn=update_input_image,
|
| 147 |
+
inputs=[input_image],
|
| 148 |
+
outputs=[input_image])
|
| 149 |
+
|
| 150 |
model_type.change(fn=update_model_name,
|
| 151 |
inputs=[model_type],
|
| 152 |
outputs=[model_name])
|