Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,9 @@
|
|
| 1 |
-
# check pytorch installation:
|
| 2 |
-
import torch, torchvision
|
| 3 |
-
try:
|
| 4 |
-
import detectron2
|
| 5 |
-
except:
|
| 6 |
-
import os
|
| 7 |
-
os.system('pip install git+https://github.com/facebookresearch/detectron2.git')
|
| 8 |
import gradio as gr
|
| 9 |
-
|
| 10 |
-
# Setup detectron2 logger
|
| 11 |
-
import detectron2
|
| 12 |
-
from detectron2.utils.logger import setup_logger
|
| 13 |
-
|
| 14 |
-
# import some common libraries
|
| 15 |
-
import numpy as np
|
| 16 |
-
import os, json, cv2, random
|
| 17 |
-
|
| 18 |
-
# import some common detectron2 utilities
|
| 19 |
-
from detectron2 import model_zoo
|
| 20 |
-
from detectron2.engine import DefaultPredictor
|
| 21 |
-
from detectron2.config import get_cfg
|
| 22 |
-
from detectron2.utils.visualizer import Visualizer
|
| 23 |
-
from detectron2.data import MetadataCatalog, DatasetCatalog
|
| 24 |
-
from PIL import Image
|
| 25 |
-
|
| 26 |
-
cfg = get_cfg()
|
| 27 |
-
cfg.MODEL.DEVICE='cpu'
|
| 28 |
-
cfg.merge_from_file(model_zoo.get_config_file("COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml"))
|
| 29 |
-
cfg.MODEL.WEIGHTS = "model_final.pth"
|
| 30 |
-
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 # set threshold for this model
|
| 31 |
-
predictor = DefaultPredictor(cfg)
|
| 32 |
def inference(img):
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
examples = [['input.jpg']]
|
| 40 |
-
|
| 41 |
-
gr.Interface(inference, inputs=gr.inputs.Image(type="file"), outputs=gr.outputs.Image(type="pil"),enable_queue=True,
|
| 42 |
-
examples=examples).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from Inference import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
def inference(img):
|
| 4 |
+
img = cv2.imread(img.name)
|
| 5 |
+
boxes, scores, cls_ids = prediction(img)
|
| 6 |
+
return vis(img, boxes, scores, cls_ids)
|
| 7 |
+
examples = [['input.jpg'], ['1.png']]
|
| 8 |
+
gr.Interface(inference, inputs=gr.inputs.Image(type="file"), outputs=gr.outputs.Image(type="pil"),
|
| 9 |
+
examples=examples).launch()
|
|
|
|
|
|
|
|
|
|
|
|