ayoubkirouane commited on
Commit
5c4a425
1 Parent(s): 7624210

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -15
app.py CHANGED
@@ -1,43 +1,32 @@
1
  import torch
2
  from transformers import pipeline
3
-
4
  from PIL import Image
5
-
6
  import matplotlib.pyplot as plt
7
-
8
- from random import choice
9
  import io
10
 
11
  detector50 = pipeline(model="TuningAI/DETR-BASE_Marine")
12
 
13
  import gradio as gr
14
 
15
- COLORS = ["#ff7f7f", "#ff7fbf", "#ff7fff", "#bf7fff",
16
- "#7f7fff", "#7fbfff", "#7fffff", "#7fffbf",
17
- "#7fff7f", "#bfff7f", "#ffff7f", "#ffbf7f"]
18
-
19
  fdic = {
20
- "family" : "Impact",
21
  "style" : "italic",
22
  "size" : 10,
23
  "color" : "red",
24
  "weight" : "bold"
25
  }
26
-
27
-
28
  def get_figure(in_pil_img, in_results):
29
  plt.figure(figsize=(16, 10))
30
  plt.imshow(in_pil_img)
31
  ax = plt.gca()
32
 
33
  for prediction in in_results:
34
- selected_color = choice(COLORS)
35
 
36
  x, y = prediction['box']['xmin'], prediction['box']['ymin'],
37
  w, h = prediction['box']['xmax'] - prediction['box']['xmin'], prediction['box']['ymax'] - prediction['box']['ymin']
38
-
39
  ax.add_patch(plt.Rectangle((x, y), w, h, fill=False, color=selected_color, linewidth=3))
40
- ax.text(x, y, f"{prediction['label']}: {round(prediction['score']*100, 1)}%", fontdict=fdic)
41
 
42
  plt.axis("off")
43
 
@@ -61,6 +50,6 @@ with gr.Blocks(title="DETR Object Detection") as demo:
61
  with gr.Row():
62
  input_image = gr.Image(label="Input image", type="pil")
63
  output_image = gr.Image(label="Output image with predicted instances", type="pil")
64
- send_btn = gr.Button("Infer")
65
  send_btn.click(fn=infer, inputs=input_image, outputs=[output_image])
66
  demo.launch(debug=True)
 
1
  import torch
2
  from transformers import pipeline
 
3
  from PIL import Image
 
4
  import matplotlib.pyplot as plt
 
 
5
  import io
6
 
7
  detector50 = pipeline(model="TuningAI/DETR-BASE_Marine")
8
 
9
  import gradio as gr
10
 
 
 
 
 
11
  fdic = {
 
12
  "style" : "italic",
13
  "size" : 10,
14
  "color" : "red",
15
  "weight" : "bold"
16
  }
17
+ labels_ = { "LABEL_0":"None" , "LABEL_1": "Boat" ,"LABEL_2": "Car" ,"LABEL_3" : "Dock" , "LABEL_4" : "Jetski" ,"LABEL_5" : "Lift"}
 
18
  def get_figure(in_pil_img, in_results):
19
  plt.figure(figsize=(16, 10))
20
  plt.imshow(in_pil_img)
21
  ax = plt.gca()
22
 
23
  for prediction in in_results:
24
+ selected_color ="#008000"
25
 
26
  x, y = prediction['box']['xmin'], prediction['box']['ymin'],
27
  w, h = prediction['box']['xmax'] - prediction['box']['xmin'], prediction['box']['ymax'] - prediction['box']['ymin']
 
28
  ax.add_patch(plt.Rectangle((x, y), w, h, fill=False, color=selected_color, linewidth=3))
29
+ ax.text(x, y, f"{labels_[prediction['label']]}: {round(prediction['score']*100, 1)}%", fontdict=fdic)
30
 
31
  plt.axis("off")
32
 
 
50
  with gr.Row():
51
  input_image = gr.Image(label="Input image", type="pil")
52
  output_image = gr.Image(label="Output image with predicted instances", type="pil")
53
+ send_btn = gr.Button("start")
54
  send_btn.click(fn=infer, inputs=input_image, outputs=[output_image])
55
  demo.launch(debug=True)