Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ except:
|
|
| 5 |
os.system('pip install git+https://github.com/facebookresearch/detectron2.git')
|
| 6 |
import spaces
|
| 7 |
import cv2
|
| 8 |
-
import supervision as sv
|
| 9 |
import torch
|
| 10 |
from matplotlib.pyplot import axis
|
| 11 |
import gradio as gr
|
|
@@ -32,15 +31,8 @@ cfg.MODEL.ROI_HEADS.NUM_CLASSES = 11
|
|
| 32 |
cfg.MODEL.WEIGHTS = model_path
|
| 33 |
|
| 34 |
my_metadata = MetadataCatalog.get("dbmdz_coco_all")
|
| 35 |
-
#my_metadata.thing_classes = ["GRAFFITI", "FADED_SIGNAGE","POTHOLES","GARBAGE","CONSTRUCTION_ROAD","BROKEN_SIGNAGE","BAD_STREETLIGHT","BAD_BILLBOARD","SAND_ON_ROAD","CLUTTER_SIDEWALK","UNKEPT_FACADE"]
|
| 36 |
my_metadata.thing_classes = ["None", "BAD_BILLBOARD","BROKEN_SIGNAGE","CLUTTER_SIDEWALK","CONSTRUCTION_ROAD","FADED_SIGNAGE","GARBAGE","GRAFFITI","POTHOLES","SAND_ON_ROAD","UNKEPT_FACADE"]
|
| 37 |
|
| 38 |
-
# #smart_dict={'GRAFFITI' : 0.0 , 'FADED_SIGNAGE': 1.0 , 'POTHOLES': 2.0,
|
| 39 |
-
# 'GARBAGE' : 3.0 , 'CONSTRUCTION_ROAD': 4.0 , 'BROKEN_SIGNAGE': 5.0,
|
| 40 |
-
# 'BAD_STREETLIGHT' : 6.0 , 'BAD_BILLBOARD': 7.0 , 'SAND_ON_ROAD':8.0,
|
| 41 |
-
# 'CLUTTER_SIDEWALK' : 9.0 , 'UNKEPT_FACADE': 10.0}
|
| 42 |
-
if not torch.cuda.is_available():
|
| 43 |
-
cfg.MODEL.DEVICE = "cpu"
|
| 44 |
|
| 45 |
|
| 46 |
def predict_frame(frame,_):
|
|
@@ -57,6 +49,7 @@ def inference(image_url, image, min_score):
|
|
| 57 |
cfg.MODEL.DEVICE = "cpu"
|
| 58 |
else:
|
| 59 |
cfg.MODEL.DEVICE = "cuda"
|
|
|
|
| 60 |
if image_url:
|
| 61 |
r = requests.get(image_url)
|
| 62 |
if r:
|
|
@@ -81,7 +74,6 @@ def inference(image_url, image, min_score):
|
|
| 81 |
def process_vid(video_path):
|
| 82 |
|
| 83 |
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.3
|
| 84 |
-
torch.cuda.empty_cache()
|
| 85 |
if not torch.cuda.is_available():
|
| 86 |
cfg.MODEL.DEVICE = "cpu"
|
| 87 |
else:
|
|
@@ -148,39 +140,10 @@ def process_vid(video_path):
|
|
| 148 |
return output_path
|
| 149 |
|
| 150 |
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
def infer_video(video_path):
|
| 154 |
-
sv.process_video(source_path=video_path, target_path=f"result.mp4", callback=predict_frame)
|
| 155 |
-
return f"result.mp4"
|
| 156 |
-
|
| 157 |
-
|
| 158 |
title = "Smartathon Phase2 Demo - Baseer"
|
| 159 |
description = "This demo introduces an interactive playground for our trained Detectron2 model."
|
| 160 |
article = '<p>Detectron model is available from our repository <a href="https://github.com/asalhi/Smartathon-Baseer">here</a>.</p>'
|
| 161 |
|
| 162 |
-
# gr.Interface(
|
| 163 |
-
# inference,
|
| 164 |
-
# [gr.inputs.Textbox(label="Image URL", placeholder=""),
|
| 165 |
-
# gr.inputs.Image(type="filepath", image_mode="RGB", source="upload", optional=False, label="Input Image"),
|
| 166 |
-
# gr.Slider(minimum=0.0, maximum=1.0, value=0.4, label="Minimum score"),
|
| 167 |
-
# ],
|
| 168 |
-
# gr.outputs.Image(type="pil", label="Output"),
|
| 169 |
-
# #gr.Examples(['./d1.jpeg', './d2.jpeg', './d3.jpeg','./d4.jpeg','./d5.jpeg','./d6.jpeg'], inputs=gr.inputs.Image(type="filepath", image_mode="RGB", source="upload", optional=False, label="Input Image")),
|
| 170 |
-
# title=title,
|
| 171 |
-
# description=description,
|
| 172 |
-
# article=article,
|
| 173 |
-
# #examples=[['./d1.jpeg'], ['./d2.jpeg'], ['./d3.jpeg'],['./d4.jpeg'],['./d5.jpeg'],['./d6.jpeg']],
|
| 174 |
-
# examples = gr.Examples(['./d1.jpeg', './d2.jpeg', './d3.jpeg','./d4.jpeg','./d5.jpeg','./d6.jpeg'], inputs=gr.inputs.Image(type="filepath", image_mode="RGB", source="upload", optional=False, label="Input Image")),
|
| 175 |
-
# cache_examples=False).launch()
|
| 176 |
-
# #examples=['./d1.jpeg', './d2.jpeg', './d3.jpeg','./d4.jpeg','./d5.jpeg','./d6.jpeg']
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
# gr.Examples(['./d1.jpeg', './d2.jpeg', './d3.jpeg','./d4.jpeg','./d5.jpeg','./d6.jpeg'], inputs=input_image)
|
| 182 |
-
|
| 183 |
-
|
| 184 |
|
| 185 |
|
| 186 |
|
|
|
|
| 5 |
os.system('pip install git+https://github.com/facebookresearch/detectron2.git')
|
| 6 |
import spaces
|
| 7 |
import cv2
|
|
|
|
| 8 |
import torch
|
| 9 |
from matplotlib.pyplot import axis
|
| 10 |
import gradio as gr
|
|
|
|
| 31 |
cfg.MODEL.WEIGHTS = model_path
|
| 32 |
|
| 33 |
my_metadata = MetadataCatalog.get("dbmdz_coco_all")
|
|
|
|
| 34 |
my_metadata.thing_classes = ["None", "BAD_BILLBOARD","BROKEN_SIGNAGE","CLUTTER_SIDEWALK","CONSTRUCTION_ROAD","FADED_SIGNAGE","GARBAGE","GRAFFITI","POTHOLES","SAND_ON_ROAD","UNKEPT_FACADE"]
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
def predict_frame(frame,_):
|
|
|
|
| 49 |
cfg.MODEL.DEVICE = "cpu"
|
| 50 |
else:
|
| 51 |
cfg.MODEL.DEVICE = "cuda"
|
| 52 |
+
print( cfg.MODEL.DEVICE)
|
| 53 |
if image_url:
|
| 54 |
r = requests.get(image_url)
|
| 55 |
if r:
|
|
|
|
| 74 |
def process_vid(video_path):
|
| 75 |
|
| 76 |
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.3
|
|
|
|
| 77 |
if not torch.cuda.is_available():
|
| 78 |
cfg.MODEL.DEVICE = "cpu"
|
| 79 |
else:
|
|
|
|
| 140 |
return output_path
|
| 141 |
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
title = "Smartathon Phase2 Demo - Baseer"
|
| 144 |
description = "This demo introduces an interactive playground for our trained Detectron2 model."
|
| 145 |
article = '<p>Detectron model is available from our repository <a href="https://github.com/asalhi/Smartathon-Baseer">here</a>.</p>'
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
|
| 149 |
|