tidalove commited on
Commit
0a89fd3
·
verified ·
1 Parent(s): 02401bf

bbox calculation changes

Browse files
Files changed (1) hide show
  1. tools/demo_api.py +8 -3
tools/demo_api.py CHANGED
@@ -74,6 +74,11 @@ class Predictor(object):
74
  img_info["raw_img"] = img
75
 
76
  ratio = min(self.test_size[0] / img.shape[0], self.test_size[1] / img.shape[1])
 
 
 
 
 
77
  img_info["ratio"] = ratio
78
 
79
  img, _ = self.preproc(img, None, self.test_size)
@@ -94,7 +99,7 @@ class Predictor(object):
94
  self.nmsthre, class_agnostic=True
95
  )
96
  logger.info("Infer time: {:.4f}s".format(time.time() - t0))
97
- return outputs, img_info
98
 
99
  def visual(self, output, img_info, cls_conf=0.35):
100
  ratio = img_info["ratio"]
@@ -163,7 +168,7 @@ def run_detection(predictor, path):
163
 
164
  for img_id, image_name in enumerate(files):
165
 
166
- outputs, img_info = predictor.inference(image_name)
167
  ratio = img_info["ratio"]
168
 
169
  img_entry = {"id": img_id,
@@ -176,7 +181,7 @@ def run_detection(predictor, path):
176
  print(output)
177
  ann_entry = {"id": id,
178
  "image_id": img_id,
179
- "bbox": (output[:4] / ratio).tolist(),
180
  "cls": output[6].item(),
181
  "score": (output[4] * output[5]).item() }
182
  ann_list.append(ann_entry)
 
74
  img_info["raw_img"] = img
75
 
76
  ratio = min(self.test_size[0] / img.shape[0], self.test_size[1] / img.shape[1])
77
+ pad = [0,0,0,0]
78
+ pad[1] = ( self.test_size[0] - img.shape[0] * ratio ) / 2
79
+ pad[0] = ( self.test_size[1] - img.shape[1] * ratio ) / 2
80
+ pad[2] = pad[0]
81
+ pad[3] = pad[1]
82
  img_info["ratio"] = ratio
83
 
84
  img, _ = self.preproc(img, None, self.test_size)
 
99
  self.nmsthre, class_agnostic=True
100
  )
101
  logger.info("Infer time: {:.4f}s".format(time.time() - t0))
102
+ return outputs, img_info, pad
103
 
104
  def visual(self, output, img_info, cls_conf=0.35):
105
  ratio = img_info["ratio"]
 
168
 
169
  for img_id, image_name in enumerate(files):
170
 
171
+ outputs, img_info, pad = predictor.inference(image_name)
172
  ratio = img_info["ratio"]
173
 
174
  img_entry = {"id": img_id,
 
181
  print(output)
182
  ann_entry = {"id": id,
183
  "image_id": img_id,
184
+ "bbox": ((output[:4] - pad) / ratio).tolist(),
185
  "cls": output[6].item(),
186
  "score": (output[4] * output[5]).item() }
187
  ann_list.append(ann_entry)