Assume that I have two arrays of boxes, each of which has the shape (?, b1, 4)
and (?, b2, 4)
respectively (treat ?
as a unknown batch size):
box1: [[[1,2,3,4], [2,3,4,5], [3,4,5,6]...]...]
box2: [[[4,3,2,1], [3,2,5,4], [4,3,5,6]...]...]
(the number above are set arbitarily)
I want to:
in each batch, for each box A in
box1
, find inbox2
the box B which has the maximum IOU (intersection over union) with A (in the same batch, of course), and then append the tuple (A, B) to a list list_max.append to list_nonmax all the boxes in
box2
that does not have maximum IOU with any box inbox1
(separated by batch, of course)
You can assume that:
b1 and b2 are both python variables, not tensorflow tensor.
methods for calculating IOU between single box or between batch of boxes already exists and can be used literally:
iou_single_box(box1, box2)
: both box1 and box2 are of shape(4,)
.iou_multiple_boxes(bbox1, bbox2)
: both bbox1 and bbox2 are of shape(b1, 4)
and(b2, 4)
respectively.iou_batch_boxes(bbbox1, bbbox2)
: both bbbox1 and bbbox2 are of shape(?, b1, 4)
and(?, b2, 4)
respectively (treat?
as a unknown batch size).
I found these particularly hard in tensorflow, especially for the list_nonmax case, because, whereas it is easy to use padding and then tf.reduce_max()
to get box tuples with maximum iou, it is impossible to remember their index and then extract out boxes for list_nonmax.