From 8846b50c7f75cbc24dabec862c835f2ba59e6a72 Mon Sep 17 00:00:00 2001 From: luoyang Date: Mon, 1 Feb 2021 11:06:23 +0800 Subject: [PATCH] fix cutout issue & pad doc --- .../ccsrc/minddata/dataset/api/vision.cc | 8 ++++- .../ccsrc/minddata/dataset/include/vision.h | 29 +++++++++++-------- .../dataset/kernels/image/image_utils.cc | 2 +- mindspore/dataset/vision/c_transforms.py | 12 ++++---- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/api/vision.cc b/mindspore/ccsrc/minddata/dataset/api/vision.cc index 7f43c44e94..60cb3a891e 100644 --- a/mindspore/ccsrc/minddata/dataset/api/vision.cc +++ b/mindspore/ccsrc/minddata/dataset/api/vision.cc @@ -901,8 +901,14 @@ std::shared_ptr RandomAffineOperation::Build() { if (translate_range_.size() == 2) { translate_range_.resize(4); } + std::vector fill_value = {fill_value_[0], fill_value_[0], fill_value_[0]}; + if (fill_value_.size() == 3) { + fill_value[1] = fill_value_[1]; + fill_value[2] = fill_value_[2]; + } + auto tensor_op = std::make_shared(degrees_, translate_range_, scale_range_, shear_ranges_, - interpolation_, fill_value_); + interpolation_, fill_value); return tensor_op; } diff --git a/mindspore/ccsrc/minddata/dataset/include/vision.h b/mindspore/ccsrc/minddata/dataset/include/vision.h index 7615ce0a27..4775631b4b 100644 --- a/mindspore/ccsrc/minddata/dataset/include/vision.h +++ b/mindspore/ccsrc/minddata/dataset/include/vision.h @@ -198,14 +198,14 @@ std::shared_ptr NormalizePad(const std::vector &me /// \brief Function to create a Pad TensorOp /// \notes Pads the image according to padding parameters /// \param[in] padding A vector representing the number of pixels to pad the image -/// If vector has one value, it pads all sides of the image with that value +/// If vector has one value, it pads all sides of the image with that value. /// If vector has two values, it pads left and right with the first and -/// top and bottom with the second value +/// top and bottom with the second value. /// If vector has four values, it pads left, top, right, and bottom with -/// those values respectively +/// those values respectively. /// \param[in] fill_value A vector representing the pixel intensity of the borders if the padding_mode is -/// BorderType.kConstant. If 3 values are provided, -/// it is used to fill R, G, B channels respectively +/// BorderType.kConstant. If 1 value is provided, it is used for all RGB channels. If 3 values are provided, +/// it is used to fill R, G, B channels respectively. /// \param[in] padding_mode The method of padding (default=BorderType.kConstant) /// Can be any of /// [BorderType.kConstant, BorderType.kEdge, BorderType.kReflect, BorderType.kSymmetric] @@ -230,8 +230,9 @@ std::shared_ptr Pad(std::vector padding, std::vector RandomAffine( const std::vector °rees, const std::vector &translate_range = {0.0, 0.0, 0.0, 0.0}, @@ -272,8 +273,9 @@ std::shared_ptr RandomColorAdjust(std::vector /// it pads the left, top, right and bottom respectively. /// \param[in] pad_if_needed A boolean whether to pad the image if either side is smaller than /// the given output size. -/// \param[in] fill_value A vector representing the pixel intensity of the borders, it is used to -/// fill R, G, B channels respectively. +/// \param[in] fill_value A vector representing the pixel intensity of the borders if the padding_mode is +/// BorderType.kConstant. If 1 value is provided, it is used for all RGB channels. +/// If 3 values are provided, it is used to fill R, G, B channels respectively. /// \return Shared pointer to the current TensorOperation. std::shared_ptr RandomCrop(std::vector size, std::vector padding = {0, 0, 0, 0}, bool pad_if_needed = false, std::vector fill_value = {0, 0, 0}, @@ -305,8 +307,9 @@ std::shared_ptr RandomCropDecodeResize( /// it pads the left, top, right and bottom respectively. /// \param[in] pad_if_needed A boolean whether to pad the image if either side is smaller than /// the given output size. -/// \param[in] fill_value A vector representing the pixel intensity of the borders, it is used to -/// fill R, G, B channels respectively. +/// \param[in] fill_value A vector representing the pixel intensity of the borders if the padding_mode is +/// BorderType.kConstant. If 1 value is provided, it is used for all RGB channels. +/// If 3 values are provided, it is used to fill R, G, B channels respectively. /// \param[in] padding_mode The method of padding (default=BorderType::kConstant).It can be any of /// [BorderType::kConstant, BorderType::kEdge, BorderType::kReflect, BorderType::kSymmetric]. /// \return Shared pointer to the current TensorOperation. @@ -389,7 +392,9 @@ std::shared_ptr RandomResizedCropWithBBox( /// \param[in] resample An enum for the mode of interpolation /// \param[in] expand A boolean representing whether the image is expanded after rotation /// \param[in] center A float vector of size 2, representing the x and y center of rotation. -/// \param[in] fill_value A uint8_t vector of size 3, representing the rgb value of the fill color +/// \param[in] fill_value A vector representing the value to fill the area outside the transform +/// in the output image. If 1 value is provided, it is used for all RGB channels. +/// If 3 values are provided, it is used to fill R, G, B channels respectively. /// \return Shared pointer to the current TensorOp std::shared_ptr RandomRotation( std::vector degrees, InterpolationMode resample = InterpolationMode::kNearestNeighbour, bool expand = false, diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc index c70fff9c8e..e1c9fb57fd 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc @@ -949,7 +949,7 @@ Status Erase(const std::shared_ptr &input, std::shared_ptr *outp RETURN_STATUS_UNEXPECTED("CutOut: load image failed."); } if (input_cv->Rank() != 3 || num_channels != 3) { - RETURN_STATUS_UNEXPECTED("CutOut: image shape is not or ."); + RETURN_STATUS_UNEXPECTED("CutOut: image shape is not ."); } cv::Mat input_img = input_cv->mat(); int32_t image_h = input_cv->shape()[0]; diff --git a/mindspore/dataset/vision/c_transforms.py b/mindspore/dataset/vision/c_transforms.py index 5496dd5c5d..8ec3fe0a9c 100644 --- a/mindspore/dataset/vision/c_transforms.py +++ b/mindspore/dataset/vision/c_transforms.py @@ -438,8 +438,8 @@ class Pad(ImageTensorOperation): Args: padding (Union[int, sequence]): The number of pixels to pad the image. If a single number is provided, it pads all borders with this value. - If a tuple or list of 2 values are provided, it pads the (left and top) - with the first value and (right and bottom) with the second value. + If a tuple or list of 2 values are provided, it pads left and right + with the first value and top and bottom with the second value. If 4 values are provided as a list or tuple, it pads the left, top, right and bottom respectively. fill_value (Union[int, tuple], optional): The pixel intensity of the borders, only valid for @@ -674,8 +674,8 @@ class RandomCrop(ImageTensorOperation): padding (Union[int, sequence], optional): The number of pixels to pad the image (default=None). If padding is not None, pad image firstly with padding values. If a single number is provided, pad all borders with this value. - If a tuple or list of 2 values are provided, pad the (left and top) - with the first value and (right and bottom) with the second value. + If a tuple or list of 2 values are provided, it pads left and right + with the first value and top and bottom with the second value. If 4 values are provided as a list or tuple, pad the left, top, right and bottom respectively. pad_if_needed (bool, optional): Pad the image if either side is smaller than @@ -790,8 +790,8 @@ class RandomCropWithBBox(ImageTensorOperation): padding (Union[int, sequence], optional): The number of pixels to pad the image (default=None). If padding is not None, first pad image with padding values. If a single number is provided, pad all borders with this value. - If a tuple or list of 2 values are provided, pad the (left and top) - with the first value and (right and bottom) with the second value. + If a tuple or list of 2 values are provided, it pads left and right + with the first value and top and bottom with the second value. If 4 values are provided as a list or tuple, pad the left, top, right and bottom respectively. pad_if_needed (bool, optional): Pad the image if either side is smaller than the given output size (default=False).