Converts Python padding to C++ padding for ops which take EXPLICIT padding. Args: padding: the `padding` argument for a Python op which supports EXPLICIT padding. Returns: (padding, explicit_paddings) pair, which should be passed as attributes to a C++ op. Raises: Valu
(padding)
| 1589 | |
| 1590 | |
| 1591 | def _convert_padding(padding): |
| 1592 | """Converts Python padding to C++ padding for ops which take EXPLICIT padding. |
| 1593 | |
| 1594 | Args: |
| 1595 | padding: the `padding` argument for a Python op which supports EXPLICIT |
| 1596 | padding. |
| 1597 | |
| 1598 | Returns: |
| 1599 | (padding, explicit_paddings) pair, which should be passed as attributes to a |
| 1600 | C++ op. |
| 1601 | |
| 1602 | Raises: |
| 1603 | ValueError: If padding is invalid. |
| 1604 | """ |
| 1605 | explicit_paddings = [] |
| 1606 | if padding == "EXPLICIT": |
| 1607 | # Give a better error message if EXPLICIT is passed. |
| 1608 | raise ValueError('"EXPLICIT" is not a valid value for the padding ' |
| 1609 | "parameter. To use explicit padding, the padding " |
| 1610 | "parameter must be a list.") |
| 1611 | if isinstance(padding, (list, tuple)): |
| 1612 | for i, dim_paddings in enumerate(padding): |
| 1613 | if not isinstance(dim_paddings, (list, tuple)): |
| 1614 | raise ValueError("When padding is a list, each element of padding must " |
| 1615 | "be a list/tuple of size 2. Element with index %d of " |
| 1616 | "padding is not a list/tuple" % i) |
| 1617 | if len(dim_paddings) != 2: |
| 1618 | raise ValueError("When padding is a list, each element of padding must " |
| 1619 | "be a list/tuple of size 2. Element with index %d of " |
| 1620 | "padding has size %d" % (i, len(dim_paddings))) |
| 1621 | explicit_paddings.extend(dim_paddings) |
| 1622 | if len(padding) != 4: |
| 1623 | raise ValueError("When padding is a list, it must be of size 4. Got " |
| 1624 | "padding of size: %d" % len(padding)) |
| 1625 | padding = "EXPLICIT" |
| 1626 | return padding, explicit_paddings |
| 1627 | |
| 1628 | |
| 1629 | @tf_export(v1=["nn.conv1d"]) |
no test coverage detected