Gabolozano commited on
Commit
a897877
·
verified ·
1 Parent(s): 6a72675

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -4,8 +4,17 @@ from transformers import pipeline, DetrForObjectDetection, DetrConfig, DetrImage
4
  import numpy as np
5
  import cv2
6
  from PIL import Image
 
 
 
 
 
 
 
 
7
  def model_is_panoptic(model_name):
8
  return "panoptic" in model_name
 
9
  def load_model(model_name, threshold):
10
  config = DetrConfig.from_pretrained(model_name, threshold=threshold)
11
  model = DetrForObjectDetection.from_pretrained(model_name, config=config)
@@ -13,6 +22,7 @@ def load_model(model_name, threshold):
13
  return pipeline(task='object-detection', model=model, image_processor=image_processor)
14
  # Initial model with default threshold
15
  od_pipe = load_model("facebook/detr-resnet-101", 0.25)
 
16
  def draw_detections(image, detections, model_name):
17
  np_image = np.array(image)
18
  np_image = cv2.cvtColor(np_image, cv2.COLOR_RGB2BGR)
@@ -38,6 +48,7 @@ def draw_detections(image, detections, model_name):
38
  final_image = cv2.cvtColor(np_image, cv2.COLOR_BGR2RGB)
39
  final_pil_image = Image.fromarray(final_image)
40
  return final_pil_image
 
41
  def get_pipeline_prediction(model_name, threshold, pil_image):
42
  global od_pipe
43
  od_pipe = load_model(model_name, threshold)
@@ -66,4 +77,5 @@ with gr.Blocks() as demo:
66
  with gr.Tab("Description"):
67
  description_output = gr.Textbox()
68
  run_button.click(get_pipeline_prediction, inputs=[model_dropdown, threshold_slider, inp_image], outputs=[output_image, output_data, description_output])
 
69
  demo.launch()
 
4
  import numpy as np
5
  import cv2
6
  from PIL import Image
7
+ import warnings
8
+ import logging
9
+ # To suppress all warnings entries
10
+ warnings.filterwarnings('ignore')
11
+
12
+ # To ignore specific loggings from the Transformers library
13
+ logging.getLogger("transformers").setLevel(logging.ERROR)
14
+
15
  def model_is_panoptic(model_name):
16
  return "panoptic" in model_name
17
+
18
  def load_model(model_name, threshold):
19
  config = DetrConfig.from_pretrained(model_name, threshold=threshold)
20
  model = DetrForObjectDetection.from_pretrained(model_name, config=config)
 
22
  return pipeline(task='object-detection', model=model, image_processor=image_processor)
23
  # Initial model with default threshold
24
  od_pipe = load_model("facebook/detr-resnet-101", 0.25)
25
+
26
  def draw_detections(image, detections, model_name):
27
  np_image = np.array(image)
28
  np_image = cv2.cvtColor(np_image, cv2.COLOR_RGB2BGR)
 
48
  final_image = cv2.cvtColor(np_image, cv2.COLOR_BGR2RGB)
49
  final_pil_image = Image.fromarray(final_image)
50
  return final_pil_image
51
+
52
  def get_pipeline_prediction(model_name, threshold, pil_image):
53
  global od_pipe
54
  od_pipe = load_model(model_name, threshold)
 
77
  with gr.Tab("Description"):
78
  description_output = gr.Textbox()
79
  run_button.click(get_pipeline_prediction, inputs=[model_dropdown, threshold_slider, inp_image], outputs=[output_image, output_data, description_output])
80
+
81
  demo.launch()