Calculate padding required to make block_shape divide input_shape. This function can be used to calculate a suitable paddings argument for use with space_to_batch_nd and batch_to_space_nd. Args: input_shape: int32 Tensor of shape [N]. block_shape: int32 Tensor of shape [N]. base_
(input_shape,
block_shape,
base_paddings=None,
name=None)
| 3127 | |
| 3128 | @tf_export("required_space_to_batch_paddings") |
| 3129 | def required_space_to_batch_paddings(input_shape, |
| 3130 | block_shape, |
| 3131 | base_paddings=None, |
| 3132 | name=None): |
| 3133 | """Calculate padding required to make block_shape divide input_shape. |
| 3134 | |
| 3135 | This function can be used to calculate a suitable paddings argument for use |
| 3136 | with space_to_batch_nd and batch_to_space_nd. |
| 3137 | |
| 3138 | Args: |
| 3139 | input_shape: int32 Tensor of shape [N]. |
| 3140 | block_shape: int32 Tensor of shape [N]. |
| 3141 | base_paddings: Optional int32 Tensor of shape [N, 2]. Specifies the minimum |
| 3142 | amount of padding to use. All elements must be >= 0. If not specified, |
| 3143 | defaults to 0. |
| 3144 | name: string. Optional name prefix. |
| 3145 | |
| 3146 | Returns: |
| 3147 | (paddings, crops), where: |
| 3148 | |
| 3149 | `paddings` and `crops` are int32 Tensors of rank 2 and shape [N, 2] |
| 3150 | satisfying: |
| 3151 | |
| 3152 | paddings[i, 0] = base_paddings[i, 0]. |
| 3153 | 0 <= paddings[i, 1] - base_paddings[i, 1] < block_shape[i] |
| 3154 | (input_shape[i] + paddings[i, 0] + paddings[i, 1]) % block_shape[i] == 0 |
| 3155 | |
| 3156 | crops[i, 0] = 0 |
| 3157 | crops[i, 1] = paddings[i, 1] - base_paddings[i, 1] |
| 3158 | |
| 3159 | Raises: ValueError if called with incompatible shapes. |
| 3160 | """ |
| 3161 | with ops.name_scope(name, "required_space_to_batch_paddings", |
| 3162 | [input_shape, block_shape]): |
| 3163 | input_shape = ops.convert_to_tensor( |
| 3164 | input_shape, dtype=dtypes.int32, name="input_shape") |
| 3165 | block_shape = ops.convert_to_tensor( |
| 3166 | block_shape, dtype=dtypes.int32, name="block_shape") |
| 3167 | |
| 3168 | block_shape.get_shape().assert_is_fully_defined() |
| 3169 | block_shape.get_shape().assert_has_rank(1) |
| 3170 | num_block_dims = block_shape.get_shape().dims[0].value |
| 3171 | if num_block_dims == 0: |
| 3172 | return zeros([0, 2], dtypes.int32), zeros([0, 2], dtypes.int32) |
| 3173 | |
| 3174 | input_shape.get_shape().assert_is_compatible_with([num_block_dims]) |
| 3175 | |
| 3176 | if base_paddings is not None: |
| 3177 | base_paddings = ops.convert_to_tensor( |
| 3178 | base_paddings, dtype=dtypes.int32, name="base_paddings") |
| 3179 | base_paddings.get_shape().assert_is_compatible_with([num_block_dims, 2]) |
| 3180 | else: |
| 3181 | base_paddings = zeros([num_block_dims, 2], dtypes.int32) |
| 3182 | |
| 3183 | const_block_shape = tensor_util.constant_value(block_shape) |
| 3184 | const_input_shape = tensor_util.constant_value(input_shape) |
| 3185 | const_base_paddings = tensor_util.constant_value(base_paddings) |
| 3186 | if (const_block_shape is not None and const_input_shape is not None and |
nothing calls this directly
no test coverage detected