(bboxes,
                       height, width,
                       offset_y, offset_x,
                       target_height, target_width)
Adapt bounding boxes to crop or pad operations.
    Coordinates are always supposed to be relative to the image.

    Arguments:
      bboxes: Tensor Nx4 with bboxes coordinates [y_min, x_min, y_max, x_max];
      height, width: Original image dimension;
      offset_y, offset_x: Offset to apply,
        negative if cropping, positive if padding;
      target_height, target_width: Target dimension after cropping / padding.
Adapt bounding boxes to crop or pad operations.
    Coordinates are always supposed to be relative to the image.
Adapt bounding boxes to crop or pad operations . Coordinates are always supposed to be relative to the image .
def bboxes_crop_or_pad(bboxes,
                       height, width,
                       offset_y, offset_x,
                       target_height, target_width):
    """Adapt bounding boxes to crop or pad operations.
    Coordinates are always supposed to be relative to the image.

    Arguments:
      bboxes: Tensor Nx4 with bboxes coordinates [y_min, x_min, y_max, x_max];
      height, width: Original image dimension;
      offset_y, offset_x: Offset to apply,
        negative if cropping, positive if padding;
      target_height, target_width: Target dimension after cropping / padding.
    """
    with tf.name_scope('bboxes_crop_or_pad'):
        # Rescale bounding boxes in pixels.
        scale = tf.cast(tf.stack([height, width, height, width]), bboxes.dtype)
        bboxes = bboxes * scale
        # Add offset.
        offset = tf.cast(tf.stack([offset_y, offset_x, offset_y, offset_x]), bboxes.dtype)
        bboxes = bboxes + offset
        # Rescale to target dimension.
        scale = tf.cast(tf.stack([target_height, target_width,
                                  target_height, target_width]), bboxes.dtype)
        bboxes = bboxes / scale
        return bboxes
def bboxes_crop_or_pad ( bboxes , height , width , offset_y , offset_x , target_height , target_width ) : with tf . name_scope ( 'bboxes_crop_or_pad' ) : # Rescale bounding boxes in pixels. scale = tf . cast ( tf . stack ( [ height , width , height , width ] ) , bboxes . dtype ) bboxes = bboxes * scale # Add offset. offset = tf . cast ( tf . stack ( [ offset_y , offset_x , offset_y , offset_x ] ) , bboxes . dtype ) bboxes = bboxes + offset # Rescale to target dimension. scale = tf . cast ( tf . stack ( [ target_height , target_width , target_height , target_width ] ) , bboxes . dtype ) bboxes = bboxes / scale return bboxes