<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/models/blob/v2.20.0/official/vision/ops/box_ops.py#L331-L390) |

Encodes boxes to targets.

    tfm.vision.box_ops.encode_boxes(
        boxes, anchors, weights=None
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `boxes` | a tensor whose last dimension is 4 representing the coordinates of boxes in ymin, xmin, ymax, xmax order. |
| `anchors` | a tensor whose shape is the same as, or `broadcastable` to `boxes`, representing the coordinates of anchors in ymin, xmin, ymax, xmax order. |
| `weights` | None or a list of four float numbers used to scale coordinates. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `encoded_boxes` | a tensor whose shape is the same as `boxes` representing the encoded box targets. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If the last dimension of boxes is not 4. |

<br />