@@ -248,13 +248,15 @@ def det_post_process_combined(params, cls_outputs, box_outputs, scales,
248248 tf .tile (
249249 tf .expand_dims (tf .range (batch_size ), axis = 1 ), [1 , max_boxes_to_draw ]),
250250 dtype = tf .float32 )
251- y = nmsed_boxes [..., 0 ] * scales
252- x = nmsed_boxes [..., 1 ] * scales
253- height = nmsed_boxes [..., 2 ] * scales - y
254- width = nmsed_boxes [..., 3 ] * scales - x
251+ image_size = params ['image_size' ]
252+ ymin = tf .clip_by_value (nmsed_boxes [..., 0 ], 0 , image_size [0 ]) * scales
253+ xmin = tf .clip_by_value (nmsed_boxes [..., 1 ], 0 , image_size [1 ]) * scales
254+ ymax = tf .clip_by_value (nmsed_boxes [..., 2 ], 0 , image_size [0 ]) * scales
255+ xmax = tf .clip_by_value (nmsed_boxes [..., 3 ], 0 , image_size [1 ]) * scales
256+
255257 detection_list = [
256- # Format: (image_ids, y, x, height, width , score, class)
257- image_ids , y , x , height , width , nmsed_scores ,
258+ # Format: (image_ids, ymin, xmin, ymax, xmax , score, class)
259+ image_ids , ymin , xmin , ymax , xmax , nmsed_scores ,
258260 tf .cast (nmsed_classes + 1 , tf .float32 )
259261 ]
260262 detections = tf .stack (detection_list , axis = 2 , name = 'detections' )
@@ -281,7 +283,7 @@ def det_post_process(params: Dict[Any, Any], cls_outputs: Dict[int, tf.Tensor],
281283
282284 Returns:
283285 detections_batch: a batch of detection results. Each detection is a tensor
284- with each row representing [image_id, x, y, width, height , score, class].
286+ with each row representing [image_id, ymin, xmin, ymax, xmax , score, class].
285287 """
286288 if not params ['batch_size' ]:
287289 # Use combined version for dynamic batch size.
@@ -318,6 +320,7 @@ def det_post_process(params: Dict[Any, Any], cls_outputs: Dict[int, tf.Tensor],
318320 classes_per_sample ,
319321 image_id = [index ],
320322 image_scale = [scales [index ]],
323+ image_size = params ['image_size' ],
321324 min_score_thresh = min_score_thresh ,
322325 max_boxes_to_draw = max_boxes_to_draw ,
323326 disable_pyfun = params .get ('disable_pyfun' ))
@@ -412,7 +415,7 @@ def visualize_image_prediction(image,
412415 Args:
413416 image: Image content in shape of [height, width, 3].
414417 prediction: a list of vector, with each vector has the format of [image_id,
415- y, x, height, width , score, class].
418+ ymin, xmin, ymax, xmax , score, class].
416419 disable_pyfun: disable pyfunc for faster post processing.
417420 label_id_mapping: a map from label id to name.
418421 **kwargs: extra parameters for vistualization, such as min_score_thresh,
@@ -430,7 +433,7 @@ def visualize_image_prediction(image,
430433 boxes [:, [0 , 1 , 2 , 3 ]] = boxes [:, [1 , 0 , 3 , 2 ]]
431434
432435 label_id_mapping = label_id_mapping or coco_id_mapping
433- boxes [:, 2 : 4 ] += boxes [:, 0 : 2 ]
436+
434437 return visualize_image (image , boxes , classes , scores , label_id_mapping ,
435438 ** kwargs )
436439
0 commit comments