liam-jemison commited on
Commit
c3634f9
1 Parent(s): 7a70a13

adding cap on output image res

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -1,12 +1,13 @@
1
  import gradio as gr
2
  from models import yolo
3
- from cv2 import COLOR_BGR2RGB, imread, cvtColor
4
  import numpy as np
5
  import pandas as pd
6
 
7
 
8
 
9
-
 
10
  with open("eggs.names") as f:
11
  classes = f.read().split("\n")
12
 
@@ -51,7 +52,20 @@ def classify(img_path, h_tiles, v_tiles):
51
  #add the width of this split to the horizontal offset
52
  h_offset += h_split.shape[0]
53
  detections = pd.DataFrame(detections, columns = ["x", "y", "h", "w", "confidence", "class", "class id"])
54
- return cvtColor(output, COLOR_BGR2RGB), detections
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  description = """
57
  Demonstration of kelp sporophyte object detection network.
@@ -67,7 +81,7 @@ description = """
67
  iface = gr.Interface(fn = classify,
68
  inputs = [gr.Image(type="filepath"), gr.Slider(minimum=1, maximum=10, value=1, step=1),
69
  gr.Slider(minimum=1, maximum=10, value=1, step=1)],
70
- outputs = [gr.Image(invert_colors=False), gr.DataFrame()],
71
  examples = [["ex1.jpg", 1, 1],
72
  ["ex2.jpg", 1, 1],
73
  ["ex3.jpg", 1, 1],
 
1
  import gradio as gr
2
  from models import yolo
3
+ from cv2 import COLOR_BGR2RGB, imread, cvtColor, resize
4
  import numpy as np
5
  import pandas as pd
6
 
7
 
8
 
9
+ MAX_H = 1000
10
+ MAX_W = 1000
11
  with open("eggs.names") as f:
12
  classes = f.read().split("\n")
13
 
 
52
  #add the width of this split to the horizontal offset
53
  h_offset += h_split.shape[0]
54
  detections = pd.DataFrame(detections, columns = ["x", "y", "h", "w", "confidence", "class", "class id"])
55
+
56
+ output = cvtColor(output, COLOR_BGR2RGB)
57
+ x,y = output.shape[0], output.shape[1]
58
+
59
+ if x > y and x > MAX_W:
60
+ new_x = MAX_W/x
61
+ new_y = (y/x)*new_x
62
+ elif y > MAX_H:
63
+ new_y = MAX_H/y
64
+ new_x = (x/y)*new_y
65
+ else:
66
+ new_x = 1
67
+ new_y = 1
68
+ return resize(output, fx = new_x, fy = new_y, dsize = None), detections
69
 
70
  description = """
71
  Demonstration of kelp sporophyte object detection network.
 
81
  iface = gr.Interface(fn = classify,
82
  inputs = [gr.Image(type="filepath"), gr.Slider(minimum=1, maximum=10, value=1, step=1),
83
  gr.Slider(minimum=1, maximum=10, value=1, step=1)],
84
+ outputs = [gr.Image(), gr.DataFrame()],
85
  examples = [["ex1.jpg", 1, 1],
86
  ["ex2.jpg", 1, 1],
87
  ["ex3.jpg", 1, 1],