SkalskiP commited on
Commit
377e9f4
·
1 Parent(s): 094752c

checkpoint selection added

Browse files
Files changed (1) hide show
  1. app.py +31 -10
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import spaces
3
  import supervision as sv
4
- from rfdetr import RFDETRBase
5
  from rfdetr.util.coco_classes import COCO_CLASSES
6
 
7
  MARKDOWN = """
@@ -23,17 +23,26 @@ RF-DETR is a real-time, transformer-based object detection model architecture de
23
  by [Roboflow](https://roboflow.com/) and released under the Apache 2.0 license.
24
  """
25
 
 
 
 
 
 
 
26
  COLOR = sv.ColorPalette.from_hex([
27
  "#ffff00", "#ff9b00", "#ff8080", "#ff66b2", "#ff66ff", "#b266ff",
28
  "#9999ff", "#3399ff", "#66ffff", "#33ff99", "#66ff66", "#99ff00"
29
  ])
30
 
31
- MODEL = RFDETRBase()
 
32
 
33
 
34
  @spaces.GPU()
35
- def inference(image, confidence):
36
- detections = MODEL.predict(image, threshold=confidence)
 
 
37
 
38
  text_scale = sv.calculate_optimal_text_scale(resolution_wh=image.size)
39
  thickness = sv.calculate_optimal_line_thickness(resolution_wh=image.size)
@@ -74,7 +83,13 @@ with gr.Blocks() as demo:
74
  step=0.05,
75
  value=0.5,
76
  )
77
- submit_button = gr.Button("Submit")
 
 
 
 
 
 
78
  with gr.Column():
79
  output_image = gr.Image(
80
  label="Input Image",
@@ -82,11 +97,17 @@ with gr.Blocks() as demo:
82
  type='pil',
83
  height=600
84
  )
 
 
 
 
 
 
85
 
86
- submit_button.click(
87
- inference,
88
- inputs=[input_image, confidence_slider],
89
- outputs=output_image
90
- )
91
 
92
  demo.launch(debug=False, show_error=True)
 
1
  import gradio as gr
2
  import spaces
3
  import supervision as sv
4
+ from rfdetr import RFDETRBase, RFDETRLarge
5
  from rfdetr.util.coco_classes import COCO_CLASSES
6
 
7
  MARKDOWN = """
 
23
  by [Roboflow](https://roboflow.com/) and released under the Apache 2.0 license.
24
  """
25
 
26
+ IMAGE_EXAMPLES = [
27
+ ['https://media.roboflow.com/supervision/image-examples/people-walking.png', 0.3, "large"],
28
+ ['https://media.roboflow.com/supervision/image-examples/vehicles.png', 0.3, "large"],
29
+ ['https://media.roboflow.com/notebooks/examples/dog-2.jpeg', 0.5, "base"],
30
+ ]
31
+
32
  COLOR = sv.ColorPalette.from_hex([
33
  "#ffff00", "#ff9b00", "#ff8080", "#ff66b2", "#ff66ff", "#b266ff",
34
  "#9999ff", "#3399ff", "#66ffff", "#33ff99", "#66ff66", "#99ff00"
35
  ])
36
 
37
+ MODEL_BASE = RFDETRBase(resolution=728)
38
+ MODEL_LARGE = RFDETRLarge(resolution=728)
39
 
40
 
41
  @spaces.GPU()
42
+ def inference(image, confidence: float, checkpoint: str):
43
+ detections = MODEL_BASE.predict(image, threshold=confidence) \
44
+ if checkpoint == "base" \
45
+ else MODEL_LARGE.predict(image, threshold=confidence)
46
 
47
  text_scale = sv.calculate_optimal_text_scale(resolution_wh=image.size)
48
  thickness = sv.calculate_optimal_line_thickness(resolution_wh=image.size)
 
83
  step=0.05,
84
  value=0.5,
85
  )
86
+ with gr.Row():
87
+ checkpoint_dropdown = gr.Dropdown(
88
+ label="Checkpoint",
89
+ choices=["base", "large"],
90
+ value="base"
91
+ )
92
+ submit_button = gr.Button("Submit")
93
  with gr.Column():
94
  output_image = gr.Image(
95
  label="Input Image",
 
97
  type='pil',
98
  height=600
99
  )
100
+ gr.Examples(
101
+ fn=inference,
102
+ examples=IMAGE_EXAMPLES,
103
+ inputs=[input_image, confidence_slider, checkpoint_dropdown],
104
+ outputs=output_image
105
+ )
106
 
107
+ submit_button.click(
108
+ inference,
109
+ inputs=[input_image, confidence_slider, checkpoint_dropdown],
110
+ outputs=output_image
111
+ )
112
 
113
  demo.launch(debug=False, show_error=True)