(
image: torch.Tensor,
padding: list[int],
fill: Optional[Union[int, float, list[float]]] = None,
padding_mode: str = "constant",
)
| 1561 | @_register_kernel_internal(pad, torch.Tensor) |
| 1562 | @_register_kernel_internal(pad, tv_tensors.Image) |
| 1563 | def pad_image( |
| 1564 | image: torch.Tensor, |
| 1565 | padding: list[int], |
| 1566 | fill: Optional[Union[int, float, list[float]]] = None, |
| 1567 | padding_mode: str = "constant", |
| 1568 | ) -> torch.Tensor: |
| 1569 | # Be aware that while `padding` has order `[left, top, right, bottom]`, `torch_padding` uses |
| 1570 | # `[left, right, top, bottom]`. This stems from the fact that we align our API with PIL, but need to use `torch_pad` |
| 1571 | # internally. |
| 1572 | torch_padding = _parse_pad_padding(padding) |
| 1573 | |
| 1574 | if padding_mode not in ("constant", "edge", "reflect", "symmetric"): |
| 1575 | raise ValueError( |
| 1576 | f"`padding_mode` should be either `'constant'`, `'edge'`, `'reflect'` or `'symmetric'`, " |
| 1577 | f"but got `'{padding_mode}'`." |
| 1578 | ) |
| 1579 | |
| 1580 | if fill is None: |
| 1581 | fill = 0 |
| 1582 | |
| 1583 | if isinstance(fill, (int, float)): |
| 1584 | return _pad_with_scalar_fill(image, torch_padding, fill=fill, padding_mode=padding_mode) |
| 1585 | elif len(fill) == 1: |
| 1586 | return _pad_with_scalar_fill(image, torch_padding, fill=fill[0], padding_mode=padding_mode) |
| 1587 | else: |
| 1588 | return _pad_with_vector_fill(image, torch_padding, fill=fill, padding_mode=padding_mode) |
| 1589 | |
| 1590 | |
| 1591 | def _pad_with_scalar_fill( |
no test coverage detected
searching dependent graphs…