!11901 fix cutout issue & pad doc

From: @luoyang42
Reviewed-by: @heleiwang,@liucunwei
Signed-off-by: @liucunwei
This commit is contained in:
mindspore-ci-bot 2021-02-02 15:44:32 +08:00 committed by Gitee
commit df2da5679d
4 changed files with 31 additions and 20 deletions

View File

@ -901,8 +901,14 @@ std::shared_ptr<TensorOp> RandomAffineOperation::Build() {
if (translate_range_.size() == 2) {
translate_range_.resize(4);
}
std::vector<uint8_t> 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<RandomAffineOp>(degrees_, translate_range_, scale_range_, shear_ranges_,
interpolation_, fill_value_);
interpolation_, fill_value);
return tensor_op;
}

View File

@ -198,14 +198,14 @@ std::shared_ptr<NormalizePadOperation> NormalizePad(const std::vector<float> &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<PadOperation> Pad(std::vector<int32_t> padding, std::vector<uint
/// if size is 2, (min_shear_x, max_shear_x, 0, 0)
/// if size is 4, (min_shear_x, max_shear_x, min_shear_y, max_shear_y)
/// \param[in] interpolation An enum for the mode of interpolation
/// \param[in] fill_value A uint8_t vector of size 3, 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 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 TensorOperation.
std::shared_ptr<RandomAffineOperation> RandomAffine(
const std::vector<float_t> &degrees, const std::vector<float_t> &translate_range = {0.0, 0.0, 0.0, 0.0},
@ -272,8 +273,9 @@ std::shared_ptr<RandomColorAdjustOperation> RandomColorAdjust(std::vector<float>
/// 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<RandomCropOperation> RandomCrop(std::vector<int32_t> size, std::vector<int32_t> padding = {0, 0, 0, 0},
bool pad_if_needed = false, std::vector<uint8_t> fill_value = {0, 0, 0},
@ -305,8 +307,9 @@ std::shared_ptr<RandomCropDecodeResizeOperation> 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<RandomResizedCropWithBBoxOperation> 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<RandomRotationOperation> RandomRotation(
std::vector<float> degrees, InterpolationMode resample = InterpolationMode::kNearestNeighbour, bool expand = false,

View File

@ -949,7 +949,7 @@ Status Erase(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *outp
RETURN_STATUS_UNEXPECTED("CutOut: load image failed.");
}
if (input_cv->Rank() != 3 || num_channels != 3) {
RETURN_STATUS_UNEXPECTED("CutOut: image shape is not <H,W,C> or <H,W>.");
RETURN_STATUS_UNEXPECTED("CutOut: image shape is not <H,W,C>.");
}
cv::Mat input_img = input_cv->mat();
int32_t image_h = input_cv->shape()[0];

View File

@ -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).