1
def cxcy_to_xy(cxcy):
    """
    Convert bounding boxes from center-size coordinates (c_x, c_y, w, h) to boundary coordinates (x_min, y_min, x_max, y_max).

    :param cxcy: bounding boxes in center-size coordinates, a tensor of size (n_boxes, 4)
    :return: bounding boxes in boundary coordinates, a tensor of size (n_boxes, 4)
    """
    return torch.cat([cxcy[:, :2] - (cxcy[:, 2:] / 2),  # x_min, y_min
                      cxcy[:, :2] + (cxcy[:, 2:] / 2)], 1)  # x_max, y_max

I want to change this torch.cat with tensorflow 2.0

1 Answers1

5

Few options depending on the API in TF you're using:

  • tf.concat - most similar to torch.cat:

    tf.concat(values, axis, name='concat')
    
  • tf.keras.layers.concatenate - if you're using Keras sequential API:

    tf.keras.layers.concatenate(values, axis=-1, **kwargs)
    
  • tf.keras.layers.Concatenate - if you're using Keras functional API:

    x = tf.keras.layers.Concatenate(axis=-1, **kwargs)(values)
    

If you're using the Keras API, this answer is informative for understanding the differences between all the Keras concatenation functions.

adamconkey
  • 4,104
  • 5
  • 32
  • 61