forked from mindspore-Ecosystem/mindspore
fix remaining problems of Pad and PadToSize
This commit is contained in:
parent
1fa90714d4
commit
72fafb9251
|
@ -23,6 +23,8 @@ mindspore.dataset.vision.c_transforms.Pad
|
|||
- **Border.REFLECT** - 以各边的边界为轴进行镜像填充,忽略边界像素值。
|
||||
- **Border.SYMMETRIC** - 以各边的边界为轴进行对称填充,包括边界像素值。
|
||||
|
||||
.. note:: 当 `padding` 输入长度为2的序列时的行为未来将从使用第一个值填充左/上边界,使用第二个值填充右/下边界,变为使用第一个值填充左/右边界,使用第二个值填充上/下边界。你也可以直接输入长度为4的序列来分别指定左、上、右和下边界的填充长度。
|
||||
|
||||
**异常:**
|
||||
|
||||
- **TypeError** - 如果 `padding` 不是int或Sequence[int]类型。
|
||||
|
|
|
@ -29,6 +29,8 @@ mindspore.dataset.vision.c_transforms.RandomCrop
|
|||
- **Border.REFLECT** - 以各边的边界为轴进行镜像填充,忽略边界像素值。
|
||||
- **Border.SYMMETRIC** - 以各边的边界为轴进行对称填充,包括边界像素值。
|
||||
|
||||
.. note:: 当 `padding` 输入长度为2的序列时的行为未来将从使用第一个值填充左/上边界,使用第二个值填充右/下边界,变为使用第一个值填充左/右边界,使用第二个值填充上/下边界。你也可以直接输入长度为4的序列来分别指定左、上、右和下边界的填充长度。
|
||||
|
||||
**异常:**
|
||||
|
||||
- **TypeError** - 如果 `size` 不是int或Sequence[int]类型。
|
||||
|
|
|
@ -27,6 +27,8 @@ mindspore.dataset.vision.c_transforms.RandomCropWithBBox
|
|||
- **Border.REFLECT** - 以各边的边界为轴进行镜像填充,忽略边界像素值。
|
||||
- **Border.SYMMETRIC** - 以各边的边界为轴进行对称填充,包括边界像素值。
|
||||
|
||||
.. note:: 当 `padding` 输入长度为2的序列时的行为未来将从使用第一个值填充左/上边界,使用第二个值填充右/下边界,变为使用第一个值填充左/右边界,使用第二个值填充上/下边界。你也可以直接输入长度为4的序列来分别指定左、上、右和下边界的填充长度。
|
||||
|
||||
**异常:**
|
||||
|
||||
- **TypeError** - 如果 `size` 不是int或Sequence[int]类型。
|
||||
|
|
|
@ -16,6 +16,8 @@ mindspore.dataset.vision.py_transforms.Pad
|
|||
- **Border.REFLECT**:以各边的边界为轴进行镜像填充,忽略边界像素值。
|
||||
- **Border.SYMMETRIC**:以各边的边界为轴进行对称填充,包括边界像素值。
|
||||
|
||||
.. note:: 当 `padding` 输入长度为2的序列时的行为未来将从使用第一个值填充左/上边界,使用第二个值填充右/下边界,变为使用第一个值填充左/右边界,使用第二个值填充上/下边界。你也可以直接输入长度为4的序列来分别指定左、上、右和下边界的填充长度。
|
||||
|
||||
**异常:**
|
||||
|
||||
- **TypeError** - 当 `padding` 的类型不为int或Sequence[int, int]。
|
||||
|
|
|
@ -18,6 +18,8 @@ mindspore.dataset.vision.py_transforms.RandomCrop
|
|||
- **Border.REFLECT**:以各边的边界为轴进行镜像填充,忽略边界像素值。
|
||||
- **Border.SYMMETRIC**:以各边的边界为轴进行对称填充,包括边界像素值。
|
||||
|
||||
.. note:: 当 `padding` 输入长度为2的序列时的行为未来将从使用第一个值填充左/上边界,使用第二个值填充右/下边界,变为使用第一个值填充左/右边界,使用第二个值填充上/下边界。你也可以直接输入长度为4的序列来分别指定左、上、右和下边界的填充长度。
|
||||
|
||||
**异常:**
|
||||
|
||||
- **TypeError** - 当 `size` 的类型不为int或Sequence[int, int]。
|
||||
|
|
|
@ -452,9 +452,10 @@ class MS_API Pad final : public TensorTransform {
|
|||
/// - BorderType.kEdge, means it pads with the last value on the edge
|
||||
/// - BorderType.kReflect, means it reflects the values on the edge omitting the last value of edge
|
||||
/// - BorderType.kSymmetric, means it reflects the values on the edge repeating the last value of edge
|
||||
/// \note The behaviour when padding is a sequence of length 2 will change from padding left/top with
|
||||
/// the first value and right/bottom with the second to left/right with the first and top/bottom with
|
||||
/// the second in the future.
|
||||
/// \note The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
/// the first value and right/bottom with the second, to padding left/right with the first one
|
||||
/// and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
/// left, top, right and bottom respectively.
|
||||
/// \par Example
|
||||
/// \code
|
||||
/// /* Define operations */
|
||||
|
@ -689,6 +690,10 @@ class MS_API RandomCrop final : public TensorTransform {
|
|||
/// - BorderType::kReflect, Reflect the values on the edge omitting the last value of edge.
|
||||
/// - BorderType::kSymmetric, Reflect the values on the edge repeating the last value of edge.
|
||||
/// \note If the input image is more than one, then make sure that the image size is the same.
|
||||
/// \note The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
/// the first value and right/bottom with the second, to padding left/right with the first one
|
||||
/// and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
/// left, top, right and bottom respectively.
|
||||
/// \par Example
|
||||
/// \code
|
||||
/// /* Define operations */
|
||||
|
@ -787,6 +792,10 @@ class MS_API RandomCropWithBBox final : public TensorTransform {
|
|||
/// - BorderType::kEdge, Fill the border with the last value on the edge.
|
||||
/// - BorderType::kReflect, Reflect the values on the edge omitting the last value of edge.
|
||||
/// - BorderType::kSymmetric, Reflect the values on the edge repeating the last value of edge.
|
||||
/// \note The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
/// the first value and right/bottom with the second, to padding left/right with the first one
|
||||
/// and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
/// left, top, right and bottom respectively.
|
||||
/// \par Example
|
||||
/// \code
|
||||
/// /* Define operations */
|
||||
|
|
|
@ -68,9 +68,10 @@ std::shared_ptr<TensorOp> PadOperation::Build() {
|
|||
pad_bottom = padding_[dimension_zero];
|
||||
break;
|
||||
case size_two:
|
||||
MS_LOG(WARNING) << "The behaviour when padding is a sequence of length 2 will change from padding left/top with "
|
||||
"the first value and right/bottom with the second to left/right with the first and top/bottom "
|
||||
"with the second in the future.";
|
||||
MS_LOG(WARNING) << "The behaviour when `padding` is a sequence of length 2 will change from padding left/top "
|
||||
"with the first value and right/bottom with the second, to padding left/right with the "
|
||||
"first one and top/bottom with the second in the future. Or you can pass in a 4-element "
|
||||
"sequence to specify left, top, right and bottom respectively.";
|
||||
pad_left = padding_[dimension_zero];
|
||||
pad_top = padding_[dimension_zero];
|
||||
pad_right = padding_[dimension_one];
|
||||
|
|
|
@ -86,6 +86,10 @@ std::shared_ptr<TensorOp> RandomCropOperation::Build() {
|
|||
pad_bottom = padding_[dimension_zero];
|
||||
break;
|
||||
case size_two:
|
||||
MS_LOG(WARNING) << "The behaviour when `padding` is a sequence of length 2 will change from padding left/top "
|
||||
"with the first value and right/bottom with the second, to padding left/right with the "
|
||||
"first one and top/bottom with the second in the future. Or you can pass in a 4-element "
|
||||
"sequence to specify left, top, right and bottom respectively.";
|
||||
pad_left = padding_[dimension_zero];
|
||||
pad_top = padding_[dimension_zero];
|
||||
pad_right = padding_[dimension_one];
|
||||
|
|
|
@ -86,6 +86,10 @@ std::shared_ptr<TensorOp> RandomCropWithBBoxOperation::Build() {
|
|||
pad_bottom = padding_[dimension_zero];
|
||||
break;
|
||||
case size_two:
|
||||
MS_LOG(WARNING) << "The behaviour when `padding` is a sequence of length 2 will change from padding left/top "
|
||||
"with the first value and right/bottom with the second, to padding left/right with the "
|
||||
"first one and top/bottom with the second in the future. Or you can pass in a 4-element "
|
||||
"sequence to specify left, top, right and bottom respectively.";
|
||||
pad_left = padding_[dimension_zero];
|
||||
pad_top = padding_[dimension_zero];
|
||||
pad_right = padding_[dimension_one];
|
||||
|
|
|
@ -46,9 +46,8 @@ import numbers
|
|||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
from mindspore import log as logger
|
||||
import mindspore._c_dataengine as cde
|
||||
from .utils import Inter, Border, ImageBatchFormat, ConvertMode, SliceMode, AutoAugmentPolicy
|
||||
from .utils import Inter, Border, ImageBatchFormat, ConvertMode, SliceMode, AutoAugmentPolicy, parse_padding
|
||||
from .validators import check_prob, check_crop, check_center_crop, check_resize_interpolation, \
|
||||
check_mix_up_batch_c, check_normalize_c, check_normalizepad_c, check_random_crop, check_random_color_adjust, \
|
||||
check_random_rotation, check_range, check_resize, check_rescale, check_pad, check_cutout, check_alpha, \
|
||||
|
@ -135,23 +134,6 @@ DE_C_CONVERT_COLOR_MODE = {ConvertMode.COLOR_BGR2BGRA: cde.ConvertMode.DE_COLOR_
|
|||
}
|
||||
|
||||
|
||||
def parse_padding(padding):
|
||||
""" Parses and prepares the padding tuple"""
|
||||
|
||||
if isinstance(padding, numbers.Number):
|
||||
padding = [padding] * 4
|
||||
if len(padding) == 2:
|
||||
logger.warning("The behaviour when padding is a sequence of length 2 will change from padding left/top "
|
||||
"with the first value and right/bottom with the second to left/right with the first and "
|
||||
"top/bottom with the second in the future.")
|
||||
left = top = padding[0]
|
||||
right = bottom = padding[1]
|
||||
padding = (left, top, right, bottom,)
|
||||
if isinstance(padding, list):
|
||||
padding = tuple(padding)
|
||||
return padding
|
||||
|
||||
|
||||
class AdjustGamma(ImageTensorOperation):
|
||||
r"""
|
||||
Apply gamma correction on input image. Input image is expected to be in [..., H, W, C] or [H, W] format.
|
||||
|
@ -899,9 +881,10 @@ class Pad(ImageTensorOperation):
|
|||
value of edge.
|
||||
|
||||
Note:
|
||||
The behaviour when padding is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second to left/right with the first and top/bottom with
|
||||
the second in the future.
|
||||
The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second, to padding left/right with the first one
|
||||
and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
left, top, right and bottom respectively.
|
||||
|
||||
Raises:
|
||||
TypeError: If `padding` is not of type int or Sequence[int].
|
||||
|
@ -1270,6 +1253,12 @@ class RandomCrop(ImageTensorOperation):
|
|||
- Border.SYMMETRIC, means it reflects the values on the edge repeating the last
|
||||
value of edge.
|
||||
|
||||
Note:
|
||||
The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second, to padding left/right with the first one
|
||||
and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
left, top, right and bottom respectively.
|
||||
|
||||
Raises:
|
||||
TypeError: If `size` is not of type int or Sequence[int].
|
||||
TypeError: If `padding` is not of type int or Sequence[int].
|
||||
|
@ -1431,6 +1420,12 @@ class RandomCropWithBBox(ImageTensorOperation):
|
|||
- Border.SYMMETRIC, means it reflects the values on the edge repeating the last
|
||||
value of edge.
|
||||
|
||||
Note:
|
||||
The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second, to padding left/right with the first one
|
||||
and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
left, top, right and bottom respectively.
|
||||
|
||||
Raises:
|
||||
TypeError: If `size` is not of type int or Sequence[int].
|
||||
TypeError: If `padding` is not of type int or Sequence[int].
|
||||
|
|
|
@ -831,9 +831,10 @@ class Pad(py_transforms.PyTensorOperation):
|
|||
- Border.SYMMETRIC, pads with reflection of the image repeating the last value on the edge.
|
||||
|
||||
Note:
|
||||
The behaviour when padding is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second to left/right with the first and top/bottom with
|
||||
the second in the future.
|
||||
The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second, to padding left/right with the first one
|
||||
and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
left, top, right and bottom respectively.
|
||||
|
||||
Raises:
|
||||
TypeError: If `padding` is not of type int or Sequence[int, int].
|
||||
|
@ -860,7 +861,7 @@ class Pad(py_transforms.PyTensorOperation):
|
|||
|
||||
@check_pad
|
||||
def __init__(self, padding, fill_value=0, padding_mode=Border.CONSTANT):
|
||||
self.padding = padding
|
||||
self.padding = parse_padding(padding)
|
||||
self.fill_value = fill_value
|
||||
self.padding_mode = DE_PY_BORDER_TYPE[padding_mode]
|
||||
self.random = False
|
||||
|
@ -1127,6 +1128,12 @@ class RandomCrop(py_transforms.PyTensorOperation):
|
|||
- Border.REFLECT, pads with reflection of the image omitting the last value on the edge.
|
||||
- Border.SYMMETRIC, pads with reflection of the image repeating the last value on the edge.
|
||||
|
||||
Note:
|
||||
The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second, to padding left/right with the first one
|
||||
and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
left, top, right and bottom respectively.
|
||||
|
||||
Raises:
|
||||
TypeError: If `size` is not of type int or Sequence[int, int].
|
||||
TypeError: If `padding` is not of type int, Sequence[int, int] or Sequence[int, int, int, int].
|
||||
|
|
|
@ -22,7 +22,6 @@ import colorsys
|
|||
import numpy as np
|
||||
from PIL import Image, ImageOps, ImageEnhance, __version__
|
||||
|
||||
from mindspore import log as logger
|
||||
from .utils import Inter
|
||||
from ..core.py_util_helpers import is_numpy
|
||||
|
||||
|
@ -902,9 +901,6 @@ def pad(img, padding, fill_value, padding_mode):
|
|||
|
||||
elif isinstance(padding, (tuple, list)):
|
||||
if len(padding) == 2:
|
||||
logger.warning("The behaviour when padding is a sequence of length 2 will change from padding left/top "
|
||||
"with the first value and right/bottom with the second to left/right with the first and "
|
||||
"top/bottom with the second in the future.")
|
||||
left = top = padding[0]
|
||||
right = bottom = padding[1]
|
||||
elif len(padding) == 4:
|
||||
|
|
|
@ -58,22 +58,19 @@ import mindspore._c_dataengine as cde
|
|||
from mindspore._c_expression import typing
|
||||
from . import py_transforms_util as util
|
||||
from .py_transforms_util import is_pil
|
||||
from .utils import Border, Inter, parse_padding
|
||||
from .utils import ImageBatchFormat, ConvertMode, SliceMode, AutoAugmentPolicy
|
||||
from .validators import check_adjust_gamma, check_alpha, check_auto_contrast, check_center_crop, check_cutout_new, \
|
||||
check_five_crop, check_hsv_to_rgb, check_linear_transform, check_mix_up, check_normalize, \
|
||||
check_normalizepad, check_num_channels, check_pad, check_positive_degrees, check_prob, check_random_affine, \
|
||||
check_random_color_adjust, check_random_crop, check_random_erasing, check_random_perspective, \
|
||||
check_random_resize_crop, check_random_rotation, check_resize_interpolation, check_rgb_to_hsv, \
|
||||
check_ten_crop, check_crop, check_mix_up_batch_c, check_range, \
|
||||
check_resize, check_rescale, check_uniform_augment_cpp, check_convert_color, check_random_auto_contrast, \
|
||||
check_random_adjust_sharpness, check_auto_augment, \
|
||||
check_bounding_box_augment_cpp, check_random_select_subpolicy_op, check_random_solarize, \
|
||||
FLOAT_MAX_INTEGER, \
|
||||
check_cut_mix_batch_c, check_posterize, check_gaussian_blur, check_rotate, check_slice_patches, check_pad_to_size
|
||||
from .utils import AutoAugmentPolicy, Border, ConvertMode, ImageBatchFormat, Inter, SliceMode, parse_padding
|
||||
from .validators import check_adjust_gamma, check_alpha, check_auto_augment, check_auto_contrast, \
|
||||
check_bounding_box_augment_cpp, check_center_crop, check_convert_color, check_crop, check_cut_mix_batch_c, \
|
||||
check_cutout_new, check_five_crop, check_gaussian_blur, check_hsv_to_rgb, check_linear_transform, check_mix_up, \
|
||||
check_mix_up_batch_c, check_normalize, check_normalizepad, check_num_channels, check_pad, check_pad_to_size, \
|
||||
check_positive_degrees, check_posterize, check_prob, check_random_adjust_sharpness, check_random_affine, \
|
||||
check_random_auto_contrast, check_random_color_adjust, check_random_crop, check_random_erasing, \
|
||||
check_random_perspective, check_random_resize_crop, check_random_rotation, check_random_select_subpolicy_op, \
|
||||
check_random_solarize, check_range, check_rescale, check_resize, check_resize_interpolation, check_rgb_to_hsv, \
|
||||
check_rotate, check_slice_patches, check_ten_crop, check_uniform_augment_cpp, FLOAT_MAX_INTEGER
|
||||
from ..core.datatypes import mstype_to_detype, nptype_to_detype
|
||||
from ..transforms.py_transforms_util import Implementation
|
||||
from ..transforms.transforms import TensorOperation, PyTensorOperation, CompoundOperation, TypeCast
|
||||
from ..transforms.transforms import CompoundOperation, PyTensorOperation, TensorOperation, TypeCast
|
||||
|
||||
|
||||
class AdjustGamma(TensorOperation, PyTensorOperation):
|
||||
|
@ -1217,9 +1214,10 @@ class Pad(TensorOperation, PyTensorOperation):
|
|||
value of edge.
|
||||
|
||||
Note:
|
||||
The behaviour when padding is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second to left/right with the first and top/bottom with
|
||||
the second in the future.
|
||||
The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second, to padding left/right with the first one
|
||||
and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
left, top, right and bottom respectively.
|
||||
|
||||
Raises:
|
||||
TypeError: If `padding` is not of type int or Sequence[int].
|
||||
|
@ -1719,6 +1717,12 @@ class RandomCrop(TensorOperation, PyTensorOperation):
|
|||
- Border.SYMMETRIC, means it reflects the values on the edge repeating the last
|
||||
value of edge.
|
||||
|
||||
Note:
|
||||
The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second, to padding left/right with the first one
|
||||
and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
left, top, right and bottom respectively.
|
||||
|
||||
Raises:
|
||||
TypeError: If `size` is not of type int or Sequence[int].
|
||||
TypeError: If `padding` is not of type int or Sequence[int].
|
||||
|
@ -1898,6 +1902,12 @@ class RandomCropWithBBox(TensorOperation):
|
|||
|
||||
value of edge.
|
||||
|
||||
Note:
|
||||
The behaviour when `padding` is a sequence of length 2 will change from padding left/top with
|
||||
the first value and right/bottom with the second, to padding left/right with the first one
|
||||
and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify
|
||||
left, top, right and bottom respectively.
|
||||
|
||||
Raises:
|
||||
TypeError: If `size` is not of type int or Sequence[int].
|
||||
TypeError: If `padding` is not of type int or Sequence[int].
|
||||
|
|
|
@ -326,9 +326,10 @@ def parse_padding(padding):
|
|||
if isinstance(padding, numbers.Number):
|
||||
padding = [padding] * 4
|
||||
if len(padding) == 2:
|
||||
logger.warning("The behaviour when padding is a sequence of length 2 will change from padding left/top "
|
||||
"with the first value and right/bottom with the second to left/right with the first and "
|
||||
"top/bottom with the second in the future.")
|
||||
logger.warning("The behaviour when `padding` is a sequence of length 2 will change from padding left/top "
|
||||
"with the first value and right/bottom with the second, to padding left/right with the "
|
||||
"first one and top/bottom with the second in the future. Or you can pass in a 4-element "
|
||||
"sequence to specify left, top, right and bottom respectively.")
|
||||
left = top = padding[0]
|
||||
right = bottom = padding[1]
|
||||
padding = (left, top, right, bottom,)
|
||||
|
|
|
@ -614,7 +614,7 @@ def check_pad_to_size(method):
|
|||
|
||||
type_check(size, (int, list, tuple), "size")
|
||||
if isinstance(size, int):
|
||||
check_positive(size, "size")
|
||||
check_pos_int32(size, "size")
|
||||
else:
|
||||
if len(size) != 2:
|
||||
raise ValueError("The size must be a sequence of length 2.")
|
||||
|
|
|
@ -142,7 +142,7 @@ def test_pad_to_size_check():
|
|||
|
||||
test_invalid_input(TypeError, "is not of type", 3.5)
|
||||
test_invalid_input(ValueError, "The size must be a sequence of length 2", ())
|
||||
test_invalid_input(ValueError, "must be greater than 0", -100)
|
||||
test_invalid_input(ValueError, "is not within the required interval", -100)
|
||||
test_invalid_input(ValueError, "is not within the required interval", (0, 50))
|
||||
|
||||
test_invalid_input(TypeError, "is not of type", 100, "5")
|
||||
|
|
Loading…
Reference in New Issue