Spaces:
Sleeping
Sleeping
test
Browse files
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import os
|
3 |
+
from io import BytesIO
|
4 |
+
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
from pathlib import Path
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
import warnings
|
10 |
+
|
11 |
+
warnings.filterwarnings("ignore")
|
12 |
+
|
13 |
+
# os.system(
|
14 |
+
# "pip install einops shapely timm yacs tensorboardX ftfy prettytable pymongo click opencv-python inflect nltk scipy scikit-learn pycocotools")
|
15 |
+
# os.system("pip install transformers")
|
16 |
+
os.system("python setup.py build develop --user")
|
17 |
+
|
18 |
+
from maskrcnn_benchmark.config import cfg
|
19 |
+
from maskrcnn_benchmark.engine.predictor_glip import GLIPDemo
|
20 |
+
|
21 |
+
# Use this command for evaluate the GLIP-T model
|
22 |
+
config_file = "configs/pretrain/glip_Swin_T_O365_GoldG.yaml"
|
23 |
+
#weight_file = "MODEL/glip_tiny_model_o365_goldg_cc_sbu.pth"
|
24 |
+
|
25 |
+
# Use this command if you want to try the GLIP-L model
|
26 |
+
# ! wget https://penzhanwu2bbs.blob.core.windows.net/data/GLIPv1_Open/models/glip_large_model.pth -O MODEL/glip_large_model.pth
|
27 |
+
# config_file = "configs/pretrain/glip_Swin_L.yaml"
|
28 |
+
# weight_file = "MODEL/glip_large_model.pth"
|
29 |
+
|
30 |
+
# update the config options with the config file
|
31 |
+
# manual override some options
|
32 |
+
#cfg.local_rank = 0
|
33 |
+
#cfg.num_gpus = 1
|
34 |
+
cfg.merge_from_file(config_file)
|
35 |
+
#cfg.merge_from_list(["MODEL.WEIGHT", weight_file])
|
36 |
+
#cfg.merge_from_list(["MODEL.DEVICE", "cuda"])
|
37 |
+
|
38 |
+
glip_demo = GLIPDemo(
|
39 |
+
cfg,
|
40 |
+
min_image_size=800,
|
41 |
+
confidence_threshold=0.7,
|
42 |
+
show_mask_heatmaps=False
|
43 |
+
)
|
44 |
+
|
45 |
+
|
46 |
+
def predict(image, text):
|
47 |
+
result, _ = glip_demo.run_on_web_image(image[:, :, [2, 1, 0]], text, 0.5)
|
48 |
+
return result[:, :, [2, 1, 0]]
|
49 |
+
|
50 |
+
|
51 |
+
image = gr.inputs.Image()
|
52 |
+
|
53 |
+
gr.Interface(
|
54 |
+
description="Object Detection in the Wild through GLIP (https://github.com/microsoft/GLIP).",
|
55 |
+
fn=predict,
|
56 |
+
inputs=["image", "text"],
|
57 |
+
outputs=[
|
58 |
+
gr.outputs.Image(
|
59 |
+
type="pil",
|
60 |
+
# label="grounding results"
|
61 |
+
),
|
62 |
+
],
|
63 |
+
examples=[
|
64 |
+
["./flickr_9472793441.jpg", "bobble heads on top of the shelf ."],
|
65 |
+
["./flickr_9472793441.jpg", "sofa . remote . dog . person . car . sky . plane ."],
|
66 |
+
["./coco_000000281759.jpg", "A green umbrella. A pink striped umbrella. A plain white umbrella."],
|
67 |
+
["./coco_000000281759.jpg", "a flowery top. A blue dress. An orange shirt ."],
|
68 |
+
["./coco_000000281759.jpg", "a car . An electricity box ."],
|
69 |
+
["./flickr_7520721.jpg", "A woman figure skater in a blue costume holds her leg by the blade of her skate ."]
|
70 |
+
],
|
71 |
+
article=Path("docs/intro.md").read_text()
|
72 |
+
).launch()
|
73 |
+
# ).launch(server_name="0.0.0.0", server_port=7000, share=True)
|
74 |
+
|
main.py
CHANGED
@@ -57,7 +57,7 @@ def run():
|
|
57 |
|
58 |
demo.launch(server_name=LOCALHOST_NAME, server_port=get_first_available_port(
|
59 |
INITIAL_PORT_VALUE, INITIAL_PORT_VALUE + TRY_NUM_PORTS
|
60 |
-
)
|
61 |
#demo.launch(server_name="0.0.0.0", server_port=7861)
|
62 |
|
63 |
|
|
|
57 |
|
58 |
demo.launch(server_name=LOCALHOST_NAME, server_port=get_first_available_port(
|
59 |
INITIAL_PORT_VALUE, INITIAL_PORT_VALUE + TRY_NUM_PORTS
|
60 |
+
))
|
61 |
#demo.launch(server_name="0.0.0.0", server_port=7861)
|
62 |
|
63 |
|