I currently have an array where each row contains x1, y1, x2, y2 and then a value for class and confidence. I managed to remove the for loop in numpy via "apply_along_axis". However now I am trying to do the same thing in Tensorflow but I can't seem to figure out how to get it to work.
Current working numpy logic:
def calc_boxes_wh(boxes):
return [np.int32(boxes[0]), np.int32(boxes[1]), np.int32(boxes[2] - boxes[0] + 1), np.int32(boxes[3] - boxes[1] + 1), boxes[4], boxes[5]]
def transform_boxes(all_boxes):
retval = np.apply_along_axis(calc_box_width_height, 1, all_boxes)
return retval
The route I started to go down was tensorflow's map_fn function as shown below, but I am getting a series of different errors across my attempts. The current error I am getting with the code shown below is this:
ValueError: The two structures don't have the same number of elements.
First structure (1 elements): dtype: 'float32'
Second structure (6 elements): tf.Tensor 'map/while/ToInt32:0' shape=() dtype=int32>, <tf.Tensor 'map/while/ToInt32_1:0' shape=() dtype=int32>, <tf.Tensor 'map/while/ToInt32_2:0' shape=() dtype=int32>, <tf.Tensor 'map/while/ToInt32_3:0' shape=() dtype=int32>, <tf.Tensor 'map/while/strided_slice_6:0' shape=() dtype=float32>, <tf.Tensor 'map/while/strided_slice_7:0' shape=() dtype=float32>]
Current code for Tensorflow attempt:
def calc_boxes_wh(boxes):
return [tf.to_int32(boxes[0]), tf.to_int32(boxes[1]), tf.to_int32(boxes[2] - boxes[0] + 1), tf.to_int32(boxes[3] - boxes[1] + 1), boxes[4], boxes[5]]
def transform_boxes(all_boxes):
return tf.map_fn(calc_box_width_height, all_boxes)
This is a snapshot of the sample dataset:
Am I going about this all wrong? Majority of the time, I have found numpy equivalents in TF but havent had luck on this one as of yet.