diff --git a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/data/bindings.cc b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/data/bindings.cc index 3500885dac7..c6cec1eb559 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/data/bindings.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/data/bindings.cc @@ -32,45 +32,37 @@ namespace mindspore { namespace dataset { PYBIND_REGISTER(ConcatenateOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "ConcatenateOp", "Tensor operation concatenate tensors.") - .def(py::init, std::shared_ptr>(), py::arg("axis"), - py::arg("prepend").none(true), py::arg("append").none(true)); + (void)py::class_>(*m, "ConcatenateOp") + .def(py::init, std::shared_ptr>()); })); -PYBIND_REGISTER(DuplicateOp, 1, ([](const py::module *m) { - (void)py::class_>(*m, "DuplicateOp", - "Duplicate tensor.") - .def(py::init<>()); - })); +PYBIND_REGISTER( + DuplicateOp, 1, ([](const py::module *m) { + (void)py::class_>(*m, "DuplicateOp").def(py::init<>()); + })); -PYBIND_REGISTER(FillOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "FillOp", "Tensor operation to return tensor filled with same value as input fill value.") - .def(py::init>()); - })); +PYBIND_REGISTER( + FillOp, 1, ([](const py::module *m) { + (void)py::class_>(*m, "FillOp").def(py::init>()); + })); PYBIND_REGISTER(MaskOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "MaskOp", "Tensor mask operation using relational comparator") + (void)py::class_>(*m, "MaskOp") .def(py::init, DataType>()); })); -PYBIND_REGISTER(OneHotOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "OneHotOp", "Tensor operation to apply one hot encoding. Takes number of classes.") - .def(py::init()); - })); +PYBIND_REGISTER( + OneHotOp, 1, ([](const py::module *m) { + (void)py::class_>(*m, "OneHotOp").def(py::init()); + })); PYBIND_REGISTER(PadEndOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "PadEndOp", "Tensor operation to pad end of tensor with a pad value.") + (void)py::class_>(*m, "PadEndOp") .def(py::init>()); })); PYBIND_REGISTER(SliceOp, 1, ([](const py::module *m) { - (void)py::class_>(*m, "SliceOp", - "Tensor slice operation.") + (void)py::class_>(*m, "SliceOp") .def(py::init()) .def(py::init([](const py::list &py_list) { std::vector c_list; @@ -105,17 +97,15 @@ PYBIND_REGISTER(SliceOp, 1, ([](const py::module *m) { })); PYBIND_REGISTER(ToFloat16Op, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "ToFloat16Op", py::dynamic_attr(), - "Tensor operator to type cast float32 data to a float16 type.") + (void)py::class_>(*m, "ToFloat16Op", + py::dynamic_attr()) .def(py::init<>()); })); PYBIND_REGISTER(TypeCastOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "TypeCastOp", "Tensor operator to type cast data to a specified type.") - .def(py::init(), py::arg("data_type")) - .def(py::init(), py::arg("data_type")); + (void)py::class_>(*m, "TypeCastOp") + .def(py::init()) + .def(py::init()); })); PYBIND_REGISTER(RelationalOp, 0, ([](const py::module *m) { diff --git a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc index 9d289f306e2..326b8c03818 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc @@ -52,7 +52,6 @@ #include "minddata/dataset/kernels/image/random_vertical_flip_op.h" #include "minddata/dataset/kernels/image/random_vertical_flip_with_bbox_op.h" #include "minddata/dataset/kernels/image/rescale_op.h" -#include "minddata/dataset/kernels/image/resize_bilinear_op.h" #include "minddata/dataset/kernels/image/resize_op.h" #include "minddata/dataset/kernels/image/resize_with_bbox_op.h" #include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.h" @@ -63,180 +62,133 @@ namespace mindspore { namespace dataset { PYBIND_REGISTER(AutoContrastOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "AutoContrastOp", "Tensor operation to apply autocontrast on an image.") - .def(py::init>(), py::arg("cutoff") = AutoContrastOp::kCutOff, - py::arg("ignore") = AutoContrastOp::kIgnore); + (void)py::class_>(*m, "AutoContrastOp") + .def(py::init>()); })); PYBIND_REGISTER(NormalizeOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "NormalizeOp", "Tensor operation to normalize an image. Takes mean and std.") - .def(py::init(), py::arg("meanR"), py::arg("meanG"), - py::arg("meanB"), py::arg("stdR"), py::arg("stdG"), py::arg("stdB")); + (void)py::class_>(*m, "NormalizeOp") + .def(py::init()); })); -PYBIND_REGISTER(EqualizeOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "EqualizeOp", "Tensor operation to apply histogram equalization on images.") - .def(py::init<>()); - })); +PYBIND_REGISTER( + EqualizeOp, 1, ([](const py::module *m) { + (void)py::class_>(*m, "EqualizeOp").def(py::init<>()); + })); PYBIND_REGISTER(InvertOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "InvertOp", "Tensor operation to apply invert on RGB images.") - .def(py::init<>()); + (void)py::class_>(*m, "InvertOp").def(py::init<>()); })); -PYBIND_REGISTER(RescaleOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "RescaleOp", "Tensor operation to rescale an image. Takes scale and shift.") - .def(py::init(), py::arg("rescale"), py::arg("shift")); - })); +PYBIND_REGISTER( + RescaleOp, 1, ([](const py::module *m) { + (void)py::class_>(*m, "RescaleOp").def(py::init()); + })); PYBIND_REGISTER(CenterCropOp, 1, ([](const py::module *m) { (void)py::class_>( *m, "CenterCropOp", "Tensor operation to crop and image in the middle. Takes height and width (optional)") - .def(py::init(), py::arg("height"), py::arg("width") = CenterCropOp::kDefWidth); + .def(py::init()); })); -PYBIND_REGISTER(MixUpBatchOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "MixUpBatchOp", "Tensor operation to mixup a batch of images") - .def(py::init(), py::arg("alpha")); - })); +PYBIND_REGISTER( + MixUpBatchOp, 1, ([](const py::module *m) { + (void)py::class_>(*m, "MixUpBatchOp").def(py::init()); + })); PYBIND_REGISTER(CutMixBatchOp, 1, ([](const py::module *m) { (void)py::class_>( *m, "CutMixBatchOp", "Tensor operation to cutmix a batch of images") - .def(py::init(), py::arg("image_batch_format"), py::arg("alpha"), - py::arg("prob")); + .def(py::init()); })); PYBIND_REGISTER(ResizeOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "ResizeOp", "Tensor operation to resize an image. Takes height, width and mode") - .def(py::init(), py::arg("targetHeight"), - py::arg("targetWidth") = ResizeOp::kDefWidth, - py::arg("interpolation") = ResizeOp::kDefInterpolation); + (void)py::class_>(*m, "ResizeOp") + .def(py::init()); })); PYBIND_REGISTER(ResizeWithBBoxOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "ResizeWithBBoxOp", "Tensor operation to resize an image. Takes height, width and mode.") - .def(py::init(), py::arg("targetHeight"), - py::arg("targetWidth") = ResizeWithBBoxOp::kDefWidth, - py::arg("interpolation") = ResizeWithBBoxOp::kDefInterpolation); + (void)py::class_>(*m, + "ResizeWithBBoxOp") + .def(py::init()); })); +//#### PYBIND_REGISTER(RandomAffineOp, 1, ([](const py::module *m) { (void)py::class_>( *m, "RandomAffineOp", "Tensor operation to apply random affine transformations on an image.") .def(py::init, std::vector, std::vector, - std::vector, InterpolationMode, std::vector>(), - py::arg("degrees") = RandomAffineOp::kDegreesRange, - py::arg("translate_range") = RandomAffineOp::kTranslationPercentages, - py::arg("scale_range") = RandomAffineOp::kScaleRange, - py::arg("shear_ranges") = RandomAffineOp::kShearRanges, - py::arg("interpolation") = RandomAffineOp::kDefInterpolation, - py::arg("fill_value") = RandomAffineOp::kFillValue); + std::vector, InterpolationMode, std::vector>()); + })); + +PYBIND_REGISTER(RandomResizeWithBBoxOp, 1, ([](const py::module *m) { + (void)py::class_>( + *m, "RandomResizeWithBBoxOp") + .def(py::init()); })); PYBIND_REGISTER(RandomPosterizeOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "RandomPosterizeOp", "Tensor operation to apply random posterize operation on an image.") - .def(py::init(), py::arg("min_bit") = RandomPosterizeOp::kMinBit, - py::arg("max_bit") = RandomPosterizeOp::kMaxBit); + (void)py::class_>(*m, + "RandomPosterizeOp") + .def(py::init()); })); -PYBIND_REGISTER( - RandomResizeWithBBoxOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "RandomResizeWithBBoxOp", - "Tensor operation to resize an image using a randomly selected interpolation. Takes height and width.") - .def(py::init(), py::arg("targetHeight"), - py::arg("targetWidth") = RandomResizeWithBBoxOp::kDefTargetWidth); - })); PYBIND_REGISTER(UniformAugOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "UniformAugOp", "Tensor operation to apply random augmentation(s).") - .def(py::init>, int32_t>(), py::arg("transforms"), - py::arg("NumOps") = UniformAugOp::kDefNumOps); + (void)py::class_>(*m, "UniformAugOp") + .def(py::init>, int32_t>()); })); + PYBIND_REGISTER(BoundingBoxAugmentOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "BoundingBoxAugmentOp", - "Tensor operation to apply a transformation on a random choice of bounding boxes.") - .def(py::init, float>(), py::arg("transform"), - py::arg("ratio") = BoundingBoxAugmentOp::kDefRatio); - })); -PYBIND_REGISTER(ResizeBilinearOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "ResizeBilinearOp", - "Tensor operation to resize an image using " - "Bilinear mode. Takes height and width.") - .def(py::init(), py::arg("targetHeight"), - py::arg("targetWidth") = ResizeBilinearOp::kDefWidth); + *m, "BoundingBoxAugmentOp") + .def(py::init, float>()); })); PYBIND_REGISTER(DecodeOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "DecodeOp", "Tensor operation to decode a jpg image") + (void)py::class_>(*m, "DecodeOp") .def(py::init<>()) - .def(py::init(), py::arg("rgb_format") = DecodeOp::kDefRgbFormat); + .def(py::init()); })); PYBIND_REGISTER(RandomHorizontalFlipOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "RandomHorizontalFlipOp", "Tensor operation to randomly flip an image horizontally.") - .def(py::init(), py::arg("probability") = RandomHorizontalFlipOp::kDefProbability); + *m, "RandomHorizontalFlipOp") + .def(py::init()); })); PYBIND_REGISTER( RandomHorizontalFlipWithBBoxOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "RandomHorizontalFlipWithBBoxOp", - "Tensor operation to randomly flip an image horizontally, while flipping bounding boxes.") - .def(py::init(), py::arg("probability") = RandomHorizontalFlipWithBBoxOp::kDefProbability); + *m, "RandomHorizontalFlipWithBBoxOp") + .def(py::init()); })); PYBIND_REGISTER(RandomVerticalFlipOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "RandomVerticalFlipOp", "Tensor operation to randomly flip an image vertically.") - .def(py::init(), py::arg("probability") = RandomVerticalFlipOp::kDefProbability); + *m, "RandomVerticalFlipOp") + .def(py::init()); })); PYBIND_REGISTER(RandomVerticalFlipWithBBoxOp, 1, ([](const py::module *m) { (void) py::class_>( - *m, "RandomVerticalFlipWithBBoxOp", - "Tensor operation to randomly flip an image vertically" - " and adjust bounding boxes.") - .def(py::init(), py::arg("probability") = RandomVerticalFlipWithBBoxOp::kDefProbability); + *m, "RandomVerticalFlipWithBBoxOp") + .def(py::init()); })); PYBIND_REGISTER( RandomCropOp, 1, ([](const py::module *m) { - (void)py::class_>(*m, "RandomCropOp", - "Gives random crop of specified size " - "Takes crop size") + (void)py::class_>(*m, "RandomCropOp") .def( - py::init(), - py::arg("cropHeight"), py::arg("cropWidth"), py::arg("padTop") = RandomCropOp::kDefPadTop, - py::arg("padBottom") = RandomCropOp::kDefPadBottom, py::arg("padLeft") = RandomCropOp::kDefPadLeft, - py::arg("padRight") = RandomCropOp::kDefPadRight, py::arg("borderType") = RandomCropOp::kDefBorderType, - py::arg("padIfNeeded") = RandomCropOp::kDefPadIfNeeded, py::arg("fillR") = RandomCropOp::kDefFillR, - py::arg("fillG") = RandomCropOp::kDefFillG, py::arg("fillB") = RandomCropOp::kDefFillB); + py::init()); })); + PYBIND_REGISTER( HwcToChwOp, 1, ([](const py::module *m) { (void)py::class_>(*m, "ChannelSwapOp").def(py::init<>()); })); + PYBIND_REGISTER( RandomCropWithBBoxOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "RandomCropWithBBoxOp", - "Gives random crop of given " - "size + adjusts bboxes " - "Takes crop size") + (void)py::class_>(*m, "RandomCropWithBBoxOp") .def( py::init(), py::arg("cropHeight"), py::arg("cropWidth"), py::arg("padTop") = RandomCropWithBBoxOp::kDefPadTop, @@ -248,124 +200,64 @@ PYBIND_REGISTER( py::arg("fillR") = RandomCropWithBBoxOp::kDefFillR, py::arg("fillG") = RandomCropWithBBoxOp::kDefFillG, py::arg("fillB") = RandomCropWithBBoxOp::kDefFillB); })); + PYBIND_REGISTER(CutOutOp, 1, ([](const py::module *m) { (void)py::class_>( *m, "CutOutOp", "Tensor operation to randomly erase a portion of the image. Takes height and width.") - .def(py::init(), py::arg("boxHeight"), - py::arg("boxWidth"), py::arg("numPatches"), py::arg("randomColor") = CutOutOp::kDefRandomColor, - py::arg("fillR") = CutOutOp::kDefFillR, py::arg("fillG") = CutOutOp::kDefFillG, - py::arg("fillB") = CutOutOp::kDefFillB); + .def(py::init()); })); + PYBIND_REGISTER(PadOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "PadOp", - "Pads image with specified color, default black, " - "Takes amount to pad for top, bottom, left, right of image, boarder type and color") - .def(py::init(), - py::arg("padTop"), py::arg("padBottom"), py::arg("padLeft"), py::arg("padRight"), - py::arg("borderTypes") = PadOp::kDefBorderType, py::arg("fillR") = PadOp::kDefFillR, - py::arg("fillG") = PadOp::kDefFillG, py::arg("fillB") = PadOp::kDefFillB); + (void)py::class_>(*m, "PadOp") + .def(py::init()); })); PYBIND_REGISTER(RandomCropDecodeResizeOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "RandomCropDecodeResizeOp", "equivalent to RandomCropAndResize but crops before decoding") - .def(py::init(), - py::arg("targetHeight"), py::arg("targetWidth"), - py::arg("scaleLb") = RandomCropDecodeResizeOp::kDefScaleLb, - py::arg("scaleUb") = RandomCropDecodeResizeOp::kDefScaleUb, - py::arg("aspectLb") = RandomCropDecodeResizeOp::kDefAspectLb, - py::arg("aspectUb") = RandomCropDecodeResizeOp::kDefAspectUb, - py::arg("interpolation") = RandomCropDecodeResizeOp::kDefInterpolation, - py::arg("maxIter") = RandomCropDecodeResizeOp::kDefMaxIter); + *m, "RandomCropDecodeResizeOp") + .def(py::init()); })); -PYBIND_REGISTER( - RandomResizeOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "RandomResizeOp", - "Tensor operation to resize an image using a randomly selected interpolation. Takes height and width.") - .def(py::init(), py::arg("targetHeight"), - py::arg("targetWidth") = RandomResizeOp::kDefTargetWidth); - })); +PYBIND_REGISTER(RandomResizeOp, 1, ([](const py::module *m) { + (void)py::class_>(*m, "RandomResizeOp") + .def(py::init()); + })); PYBIND_REGISTER(RandomColorOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "RandomColorOp", - "Tensor operation to blend an image with its grayscale version with random weights" - "Takes min and max for the range of random weights") - .def(py::init(), py::arg("min"), py::arg("max")); + (void)py::class_>(*m, "RandomColorOp") + .def(py::init()); })); PYBIND_REGISTER(RandomColorAdjustOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "RandomColorAdjustOp", - "Tensor operation to adjust an image's color randomly." - "Takes range for brightness, contrast, saturation, hue and") - .def(py::init(), - py::arg("bright_factor_start"), py::arg("bright_factor_end"), py::arg("contrast_factor_start"), - py::arg("contrast_factor_end"), py::arg("saturation_factor_start"), - py::arg("saturation_factor_end"), py::arg("hue_factor_start"), py::arg("hue_factor_end")); + *m, "RandomColorAdjustOp") + .def(py::init()); })); PYBIND_REGISTER(RandomCropAndResizeWithBBoxOp, 1, ([](const py::module *m) { (void) py::class_>( - *m, "RandomCropAndResizeWithBBoxOp", - "Tensor operation to randomly crop an image (with BBoxes) and resize to a given size." - "Takes output height and width and" - "optional parameters for lower and upper bound for aspect ratio (h/w) and scale," - "interpolation mode, and max attempts to crop") - .def(py::init(), - py::arg("targetHeight"), py::arg("targetWidth"), - py::arg("scaleLb") = RandomCropAndResizeWithBBoxOp::kDefScaleLb, - py::arg("scaleUb") = RandomCropAndResizeWithBBoxOp::kDefScaleUb, - py::arg("aspectLb") = RandomCropAndResizeWithBBoxOp::kDefAspectLb, - py::arg("aspectUb") = RandomCropAndResizeWithBBoxOp::kDefAspectUb, - py::arg("interpolation") = RandomCropAndResizeWithBBoxOp::kDefInterpolation, - py::arg("maxIter") = RandomCropAndResizeWithBBoxOp::kDefMaxIter); + *m, "RandomCropAndResizeWithBBoxOp") + .def(py::init()); })); PYBIND_REGISTER(RandomCropAndResizeOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "RandomCropAndResizeOp", - "Tensor operation to randomly crop an image and resize to a given size." - "Takes output height and width and" - "optional parameters for lower and upper bound for aspect ratio (h/w) and scale," - "interpolation mode, and max attempts to crop") - .def(py::init(), - py::arg("targetHeight"), py::arg("targetWidth"), - py::arg("scaleLb") = RandomCropAndResizeOp::kDefScaleLb, - py::arg("scaleUb") = RandomCropAndResizeOp::kDefScaleUb, - py::arg("aspectLb") = RandomCropAndResizeOp::kDefAspectLb, - py::arg("aspectUb") = RandomCropAndResizeOp::kDefAspectUb, - py::arg("interpolation") = RandomCropAndResizeOp::kDefInterpolation, - py::arg("maxIter") = RandomCropAndResizeOp::kDefMaxIter); + *m, "RandomCropAndResizeOp") + .def(py::init()); })); PYBIND_REGISTER(RandomRotationOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "RandomRotationOp", - "Tensor operation to apply RandomRotation." - "Takes a range for degrees and " - "optional parameters for rotation center and image expand") - .def( - py::init(), - py::arg("startDegree"), py::arg("endDegree"), py::arg("centerX") = RandomRotationOp::kDefCenterX, - py::arg("centerY") = RandomRotationOp::kDefCenterY, - py::arg("interpolation") = RandomRotationOp::kDefInterpolation, - py::arg("expand") = RandomRotationOp::kDefExpand, py::arg("fillR") = RandomRotationOp::kDefFillR, - py::arg("fillG") = RandomRotationOp::kDefFillG, py::arg("fillB") = RandomRotationOp::kDefFillB); + (void)py::class_>(*m, + "RandomRotationOp") + .def(py::init()); })); PYBIND_REGISTER(RandomSharpnessOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "RandomSharpnessOp", - "Tensor operation to apply RandomSharpness." - "Takes a range for degrees") - .def(py::init(), py::arg("startDegree") = RandomSharpnessOp::kDefStartDegree, - py::arg("endDegree") = RandomSharpnessOp::kDefEndDegree); + (void)py::class_>(*m, + "RandomSharpnessOp") + .def(py::init()); })); PYBIND_REGISTER(RandomSelectSubpolicyOp, 1, ([](const py::module *m) { @@ -400,23 +292,19 @@ PYBIND_REGISTER(RandomSelectSubpolicyOp, 1, ([](const py::module *m) { return std::make_shared(cpp_policy); })); })); + PYBIND_REGISTER(SoftDvppDecodeResizeJpegOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "SoftDvppDecodeResizeJpegOp", "TensorOp to use soft dvpp decode and resize jpeg image.") - .def(py::init(), py::arg("targetHeight"), py::arg("targetWidth")); + *m, "SoftDvppDecodeResizeJpegOp") + .def(py::init()); })); + PYBIND_REGISTER( SoftDvppDecodeRandomCropResizeJpegOp, 1, ([](const py::module *m) { (void) py::class_>( - *m, "SoftDvppDecodeRandomCropResizeJpegOp", - "TensorOp to use soft dvpp decode, random crop and resize jepg image.") - .def(py::init(), py::arg("targetHeight"), - py::arg("targetWidth"), py::arg("scaleLb") = RandomCropDecodeResizeOp::kDefScaleLb, - py::arg("scaleUb") = RandomCropDecodeResizeOp::kDefScaleUb, - py::arg("aspectLb") = RandomCropDecodeResizeOp::kDefAspectLb, - py::arg("aspectUb") = RandomCropDecodeResizeOp::kDefAspectUb, - py::arg("maxIter") = RandomCropDecodeResizeOp::kDefMaxIter); + *m, "SoftDvppDecodeRandomCropResizeJpegOp") + .def(py::init()); })); PYBIND_REGISTER(RandomSolarizeOp, 1, ([](const py::module *m) { diff --git a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/text/kernels/bindings.cc b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/text/kernels/bindings.cc index 5949b0f3588..995e8789c56 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/text/kernels/bindings.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/text/kernels/bindings.cc @@ -46,73 +46,50 @@ namespace dataset { #ifdef ENABLE_ICU4C PYBIND_REGISTER(BasicTokenizerOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "BasicTokenizerOp", "Tokenize a scalar tensor of UTF-8 string by specific rules.") - .def(py::init(), - py::arg("lower_case") = BasicTokenizerOp::kDefLowerCase, - py::arg("keep_whitespace") = BasicTokenizerOp::kDefKeepWhitespace, - py::arg("normalization_form") = BasicTokenizerOp::kDefNormalizationForm, - py::arg("preserve_unused_token") = BasicTokenizerOp::kDefPreserveUnusedToken, - py::arg("with_offsets") = BasicTokenizerOp::kDefWithOffsets); + (void)py::class_>(*m, + "BasicTokenizerOp") + .def(py::init()); })); PYBIND_REGISTER(WhitespaceTokenizerOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "WhitespaceTokenizerOp", "Tokenize a scalar tensor of UTF-8 string on ICU defined whitespaces.") - .def(py::init(), py::arg(" with_offsets ") = WhitespaceTokenizerOp::kDefWithOffsets); + *m, "WhitespaceTokenizerOp") + .def(py::init()); })); PYBIND_REGISTER(UnicodeScriptTokenizerOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "UnicodeScriptTokenizerOp", - "Tokenize a scalar tensor of UTF-8 string on Unicode script boundaries.") + *m, "UnicodeScriptTokenizerOp") .def(py::init<>()) - .def(py::init(), - py::arg("keep_whitespace") = UnicodeScriptTokenizerOp::kDefKeepWhitespace, - py::arg("with_offsets") = UnicodeScriptTokenizerOp::kDefWithOffsets); + .def(py::init()); })); -PYBIND_REGISTER(CaseFoldOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "CaseFoldOp", "Apply case fold operation on utf-8 string tensor") - .def(py::init<>()); - })); +PYBIND_REGISTER( + CaseFoldOp, 1, ([](const py::module *m) { + (void)py::class_>(*m, "CaseFoldOp").def(py::init<>()); + })); PYBIND_REGISTER(NormalizeUTF8Op, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "NormalizeUTF8Op", "Apply normalize operation on utf-8 string tensor.") + (void)py::class_>(*m, "NormalizeUTF8Op") .def(py::init<>()) - .def(py::init(), py::arg("normalize_form") = NormalizeUTF8Op::kDefNormalizeForm); + .def(py::init()); })); PYBIND_REGISTER(RegexReplaceOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "RegexReplaceOp", - "Replace utf-8 string tensor with 'replace' according to regular expression 'pattern'.") - .def(py::init(), py::arg("pattern"), - py::arg("replace"), py::arg("replace_all")); + (void)py::class_>(*m, "RegexReplaceOp") + .def(py::init()); })); PYBIND_REGISTER(RegexTokenizerOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "RegexTokenizerOp", "Tokenize a scalar tensor of UTF-8 string by regex expression pattern.") - .def(py::init(), py::arg("delim_pattern"), - py::arg("keep_delim_pattern"), py::arg("with_offsets") = RegexTokenizerOp::kDefWithOffsets); + (void)py::class_>(*m, + "RegexTokenizerOp") + .def(py::init()); })); + PYBIND_REGISTER(BertTokenizerOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "BertTokenizerOp", "Tokenizer used for Bert text process.") + (void)py::class_>(*m, "BertTokenizerOp") .def(py::init &, const std::string &, const int &, const std::string &, - const bool &, const bool &, const NormalizeForm &, const bool &, const bool &>(), - py::arg("vocab"), - py::arg("suffix_indicator") = std::string(WordpieceTokenizerOp::kDefSuffixIndicator), - py::arg("max_bytes_per_token") = WordpieceTokenizerOp::kDefMaxBytesPerToken, - py::arg("unknown_token") = std::string(WordpieceTokenizerOp::kDefUnknownToken), - py::arg("lower_case") = BasicTokenizerOp::kDefLowerCase, - py::arg("keep_whitespace") = BasicTokenizerOp::kDefKeepWhitespace, - py::arg("normalization_form") = BasicTokenizerOp::kDefNormalizationForm, - py::arg("preserve_unused_token") = BasicTokenizerOp::kDefPreserveUnusedToken, - py::arg("with_offsets") = WordpieceTokenizerOp::kDefWithOffsets); + const bool &, const bool &, const NormalizeForm &, const bool &, const bool &>()); })); PYBIND_REGISTER(NormalizeForm, 0, ([](const py::module *m) { @@ -128,11 +105,9 @@ PYBIND_REGISTER(NormalizeForm, 0, ([](const py::module *m) { #endif PYBIND_REGISTER(JiebaTokenizerOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "JiebaTokenizerOp", "") - .def(py::init(), - py::arg("hmm_path"), py::arg("mp_path"), py::arg("mode") = JiebaMode::kMix, - py::arg("with_offsets") = JiebaTokenizerOp::kDefWithOffsets) + (void)py::class_>(*m, + "JiebaTokenizerOp") + .def(py::init()) .def("add_word", [](JiebaTokenizerOp &self, const std::string word, int freq) { THROW_IF_ERROR(self.AddWord(word, freq)); }); @@ -140,13 +115,12 @@ PYBIND_REGISTER(JiebaTokenizerOp, 1, ([](const py::module *m) { PYBIND_REGISTER(UnicodeCharTokenizerOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "UnicodeCharTokenizerOp", "Tokenize a scalar tensor of UTF-8 string to Unicode characters.") - .def(py::init(), py::arg("with_offsets") = UnicodeCharTokenizerOp::kDefWithOffsets); + *m, "UnicodeCharTokenizerOp") + .def(py::init()); })); PYBIND_REGISTER(LookupOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "LookupOp", "Tensor operation to LookUp each word.") + (void)py::class_>(*m, "LookupOp") .def(py::init([](std::shared_ptr vocab, const py::object &py_word) { if (vocab == nullptr) { THROW_IF_ERROR(Status(StatusCode::kUnexpectedError, "vocab object type is incorrect or null.")); @@ -165,56 +139,42 @@ PYBIND_REGISTER(LookupOp, 1, ([](const py::module *m) { })); PYBIND_REGISTER(NgramOp, 1, ([](const py::module *m) { - (void)py::class_>(*m, "NgramOp", - "TensorOp performs ngram mapping.") + (void)py::class_>(*m, "NgramOp") .def(py::init &, int32_t, int32_t, const std::string &, - const std::string &, const std::string &>(), - py::arg("ngrams"), py::arg("l_pad_len"), py::arg("r_pad_len"), py::arg("l_pad_token"), - py::arg("r_pad_token"), py::arg("separator")); + const std::string &, const std::string &>()); })); -PYBIND_REGISTER( - WordpieceTokenizerOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "WordpieceTokenizerOp", "Tokenize scalar token or 1-D tokens to subword tokens.") - .def( - py::init &, const std::string &, const int &, const std::string &, const bool &>(), - py::arg("vocab"), py::arg("suffix_indicator") = std::string(WordpieceTokenizerOp::kDefSuffixIndicator), - py::arg("max_bytes_per_token") = WordpieceTokenizerOp::kDefMaxBytesPerToken, - py::arg("unknown_token") = std::string(WordpieceTokenizerOp::kDefUnknownToken), - py::arg("with_offsets") = WordpieceTokenizerOp::kDefWithOffsets); - })); +PYBIND_REGISTER(WordpieceTokenizerOp, 1, ([](const py::module *m) { + (void)py::class_>( + *m, "WordpieceTokenizerOp") + .def(py::init &, const std::string &, const int &, const std::string &, + const bool &>()); + })); PYBIND_REGISTER(SlidingWindowOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "SlidingWindowOp", "TensorOp to apply sliding window to a 1-D Tensor.") - .def(py::init(), py::arg("width"), py::arg("axis")); + (void)py::class_>(*m, "SlidingWindowOp") + .def(py::init()); })); PYBIND_REGISTER( SentencePieceTokenizerOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "SentencePieceTokenizerOp", "Tokenize scalar token or 1-D tokens to tokens by sentence piece.") + *m, "SentencePieceTokenizerOp") .def( - py::init &, const SPieceTokenizerLoadType, const SPieceTokenizerOutType>(), - py::arg("vocab"), py::arg("load_type") = SPieceTokenizerLoadType::kModel, - py::arg("out_type") = SPieceTokenizerOutType::kString) + py::init &, const SPieceTokenizerLoadType, const SPieceTokenizerOutType>()) .def(py::init(), - py::arg("model_path"), py::arg("model_filename"), py::arg("load_type") = SPieceTokenizerLoadType::kFile, - py::arg("out_type") = SPieceTokenizerOutType::kString); + const SPieceTokenizerOutType>()); })); PYBIND_REGISTER(ToNumberOp, 1, ([](const py::module *m) { - (void)py::class_>( - *m, "ToNumberOp", "TensorOp to convert strings to numbers.") - .def(py::init(), py::arg("data_type")) - .def(py::init(), py::arg("data_type")); + (void)py::class_>(*m, "ToNumberOp") + .def(py::init()) + .def(py::init()); })); PYBIND_REGISTER(TruncateSequencePairOp, 1, ([](const py::module *m) { (void)py::class_>( - *m, "TruncateSequencePairOp", "Tensor operation to truncate two tensors to a max_length") + *m, "TruncateSequencePairOp") .def(py::init()); })); diff --git a/mindspore/ccsrc/minddata/dataset/api/python/bindings/mindrecord/include/bindings.cc b/mindspore/ccsrc/minddata/dataset/api/python/bindings/mindrecord/include/bindings.cc index 10efec77c76..fe00fb86e8d 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/bindings/mindrecord/include/bindings.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/bindings/mindrecord/include/bindings.cc @@ -62,7 +62,7 @@ PYBIND_REGISTER( ShardSample, 0, ([](const py::module *m) { (void)py::class_>( *m, "MindrecordSubsetRandomSampler") - .def(py::init, uint32_t>(), py::arg("indices"), py::arg("seed") = GetSeed()); + .def(py::init, uint32_t>()); })); PYBIND_REGISTER(ShardSequentialSample, 0, ([](const py::module *m) { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/kernels/image/CMakeLists.txt index fe4c9696842..024e6f1dea5 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/CMakeLists.txt @@ -37,7 +37,6 @@ add_library(kernels-image OBJECT random_vertical_flip_with_bbox_op.cc random_sharpness_op.cc rescale_op.cc - resize_bilinear_op.cc resize_op.cc rgba_to_bgr_op.cc rgba_to_rgb_op.cc diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/resize_bilinear_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/resize_bilinear_op.cc deleted file mode 100644 index db10f5f10c3..00000000000 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/resize_bilinear_op.cc +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright 2019 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "minddata/dataset/kernels/image/resize_bilinear_op.h" -#include - -#include "minddata/dataset/util/status.h" - -namespace mindspore { -namespace dataset { -const int32_t ResizeBilinearOp::kDefWidth = 0; - -} // namespace dataset -} // namespace mindspore diff --git a/mindspore/dataset/engine/samplers.py b/mindspore/dataset/engine/samplers.py index 4e797539dcd..d8fced318f2 100644 --- a/mindspore/dataset/engine/samplers.py +++ b/mindspore/dataset/engine/samplers.py @@ -21,6 +21,7 @@ User can also define custom sampler by extending from Sampler class. import numpy as np import mindspore._c_dataengine as cde +import mindspore.dataset as ds class Sampler: """ @@ -541,7 +542,7 @@ class SubsetRandomSampler(BuiltinSampler): return self.child_sampler.is_sharded() def create_for_minddataset(self): - c_sampler = cde.MindrecordSubsetRandomSampler(self.indices) + c_sampler = cde.MindrecordSubsetRandomSampler(self.indices, ds.config.get_seed()) c_child_sampler = self.create_child_for_minddataset() c_sampler.add_child(c_child_sampler) return c_sampler diff --git a/mindspore/dataset/text/transforms.py b/mindspore/dataset/text/transforms.py index 09fbba90219..099f582f887 100644 --- a/mindspore/dataset/text/transforms.py +++ b/mindspore/dataset/text/transforms.py @@ -52,8 +52,8 @@ import mindspore._c_dataengine as cde from .utils import JiebaMode, NormalizeForm, to_str, SPieceTokenizerOutType, SPieceTokenizerLoadType from .validators import check_lookup, check_jieba_add_dict, \ - check_jieba_add_word, check_jieba_init, check_with_offsets, check_unicode_script_tokenizer,\ - check_wordpiece_tokenizer, check_regex_tokenizer, check_basic_tokenizer, check_ngram, check_pair_truncate,\ + check_jieba_add_word, check_jieba_init, check_with_offsets, check_unicode_script_tokenizer, \ + check_wordpiece_tokenizer, check_regex_tokenizer, check_basic_tokenizer, check_ngram, check_pair_truncate, \ check_to_number, check_bert_tokenizer, check_python_tokenizer, check_slidingwindow from ..core.datatypes import mstype_to_detype @@ -100,7 +100,8 @@ class SlidingWindow(cde.SlidingWindowOp): @check_slidingwindow def __init__(self, width, axis=0): - super().__init__(width=width, axis=axis) + super().__init__(width, axis) + class Ngram(cde.NgramOp): @@ -126,8 +127,7 @@ class Ngram(cde.NgramOp): @check_ngram def __init__(self, n, left_pad=("", 0), right_pad=("", 0), separator=" "): - super().__init__(ngrams=n, l_pad_len=left_pad[1], r_pad_len=right_pad[1], l_pad_token=left_pad[0], - r_pad_token=right_pad[0], separator=separator) + super().__init__(n, left_pad[1], right_pad[1], left_pad[0], right_pad[0], separator) DE_C_INTER_JIEBA_MODE = { @@ -326,6 +326,7 @@ class WordpieceTokenizer(cde.WordpieceTokenizerOp): super().__init__(self.vocab, self.suffix_indicator, self.max_bytes_per_token, self.unknown_token, self.with_offsets) + DE_C_INTER_SENTENCEPIECE_LOADTYPE = { SPieceTokenizerLoadType.FILE: cde.SPieceTokenizerLoadType.DE_SPIECE_TOKENIZER_LOAD_KFILE, SPieceTokenizerLoadType.MODEL: cde.SPieceTokenizerLoadType.DE_SPIECE_TOKENIZER_LOAD_KMODEL @@ -336,6 +337,7 @@ DE_C_INTER_SENTENCEPIECE_OUTTYPE = { SPieceTokenizerOutType.INT: cde.SPieceTokenizerOutType.DE_SPIECE_TOKENIZER_OUTTYPE_KINT } + class SentencePieceTokenizer(cde.SentencePieceTokenizerOp): """ Tokenize scalar token or 1-D tokens to tokens by sentencepiece. @@ -357,6 +359,7 @@ class SentencePieceTokenizer(cde.SentencePieceTokenizerOp): super().__init__(mode, DE_C_INTER_SENTENCEPIECE_LOADTYPE[SPieceTokenizerLoadType.MODEL], DE_C_INTER_SENTENCEPIECE_OUTTYPE[out_type]) + if platform.system().lower() != 'windows': class WhitespaceTokenizer(cde.WhitespaceTokenizerOp): """ diff --git a/mindspore/dataset/transforms/vision/c_transforms.py b/mindspore/dataset/transforms/vision/c_transforms.py index dacf5fed376..327abf9d170 100644 --- a/mindspore/dataset/transforms/vision/c_transforms.py +++ b/mindspore/dataset/transforms/vision/c_transforms.py @@ -362,7 +362,7 @@ class RandomCrop(cde.RandomCropOp): padding = (0, 0, 0, 0) else: padding = parse_padding(padding) - if isinstance(fill_value, int): # temporary fix + if isinstance(fill_value, int): fill_value = tuple([fill_value] * 3) border_type = DE_C_BORDER_TYPE[padding_mode] @@ -417,7 +417,7 @@ class RandomCropWithBBox(cde.RandomCropWithBBoxOp): else: padding = parse_padding(padding) - if isinstance(fill_value, int): # temporary fix + if isinstance(fill_value, int): fill_value = tuple([fill_value] * 3) border_type = DE_C_BORDER_TYPE[padding_mode] @@ -549,9 +549,8 @@ class Resize(cde.ResizeOp): self.interpolation = interpolation interpoltn = DE_C_INTER_MODE[interpolation] if isinstance(size, int): - super().__init__(size, interpolation=interpoltn) - else: - super().__init__(*size, interpoltn) + size = (size, 0) + super().__init__(*size, interpoltn) class ResizeWithBBox(cde.ResizeWithBBoxOp): @@ -579,9 +578,8 @@ class ResizeWithBBox(cde.ResizeWithBBoxOp): self.interpolation = interpolation interpoltn = DE_C_INTER_MODE[interpolation] if isinstance(size, int): - super().__init__(size, interpolation=interpoltn) - else: - super().__init__(*size, interpoltn) + size = (size, 0) + super().__init__(*size, interpoltn) class RandomResizedCropWithBBox(cde.RandomCropAndResizeWithBBoxOp): @@ -779,7 +777,7 @@ class RandomRotation(cde.RandomRotationOp): degrees = (-degrees, degrees) if center is None: center = (-1, -1) - if isinstance(fill_value, int): # temporary fix + if isinstance(fill_value, int): fill_value = tuple([fill_value] * 3) interpolation = DE_C_INTER_MODE[resample] super().__init__(*degrees, *center, interpolation, expand, *fill_value) @@ -816,9 +814,8 @@ class RandomResize(cde.RandomResizeOp): def __init__(self, size): self.size = size if isinstance(size, int): - super().__init__(size) - else: - super().__init__(*size) + size = (size, 0) + super().__init__(*size) class RandomResizeWithBBox(cde.RandomResizeWithBBoxOp): @@ -837,9 +834,8 @@ class RandomResizeWithBBox(cde.RandomResizeWithBBoxOp): def __init__(self, size): self.size = size if isinstance(size, int): - super().__init__(size) - else: - super().__init__(*size) + size = (size, 0) + super().__init__(*size) class HWC2CHW(cde.ChannelSwapOp): @@ -918,7 +914,7 @@ class Pad(cde.PadOp): @check_pad def __init__(self, padding, fill_value=0, padding_mode=Border.CONSTANT): padding = parse_padding(padding) - if isinstance(fill_value, int): # temporary fix + if isinstance(fill_value, int): fill_value = tuple([fill_value] * 3) padding_mode = DE_C_BORDER_TYPE[padding_mode] diff --git a/tests/ut/cpp/dataset/CMakeLists.txt b/tests/ut/cpp/dataset/CMakeLists.txt index 8681f830c6d..29454767910 100644 --- a/tests/ut/cpp/dataset/CMakeLists.txt +++ b/tests/ut/cpp/dataset/CMakeLists.txt @@ -59,7 +59,6 @@ SET(DE_UT_SRCS rename_op_test.cc repeat_op_test.cc rescale_op_test.cc - resize_bilinear_op_test.cc resize_op_test.cc resize_with_bbox_op_test.cc rgba_to_bgr_op_test.cc diff --git a/tests/ut/cpp/dataset/c_api_transforms_test.cc b/tests/ut/cpp/dataset/c_api_transforms_test.cc index e751c8a55ff..9b68c9780ba 100644 --- a/tests/ut/cpp/dataset/c_api_transforms_test.cc +++ b/tests/ut/cpp/dataset/c_api_transforms_test.cc @@ -1200,4 +1200,8 @@ TEST_F(MindDataTestPipeline, TestRandomSolarizeFail) { threshold = {1}; random_solarize = mindspore::dataset::api::vision::RandomSolarize(threshold); EXPECT_EQ(random_solarize, nullptr); + + threshold = {}; + random_solarize = mindspore::dataset::api::vision::RandomSolarize(threshold); + EXPECT_EQ(random_solarize, nullptr); } diff --git a/tests/ut/cpp/dataset/resize_bilinear_op_test.cc b/tests/ut/cpp/dataset/resize_bilinear_op_test.cc deleted file mode 100644 index 910c8af2a2b..00000000000 --- a/tests/ut/cpp/dataset/resize_bilinear_op_test.cc +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright 2019 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "common/common.h" -#include "common/cvop_common.h" -#include "minddata/dataset/kernels/image/resize_bilinear_op.h" -#include "utils/log_adapter.h" - -using namespace mindspore::dataset; -using mindspore::MsLogLevel::INFO; -using mindspore::ExceptionType::NoExceptionType; -using mindspore::LogStream; - -class MindDataTestResizeBilinearOp : public UT::CVOP::CVOpCommon { - public: - MindDataTestResizeBilinearOp() : CVOpCommon() {} -}; - -TEST_F(MindDataTestResizeBilinearOp, TestOp) { - MS_LOG(INFO) << "Doing testResizeBilinear."; - // Resizing with a factor of 0.5 - TensorShape s = input_tensor_->shape(); - int output_w = 0.5 * s[0]; - int output_h = (s[0] * output_w) / s[1]; - std::shared_ptr output_tensor; - // Resizing - std::unique_ptr op(new ResizeBilinearOp(output_h, output_w)); - Status st = op->Compute(input_tensor_, &output_tensor); - EXPECT_TRUE(st.IsOk()); - CheckImageShapeAndData(output_tensor, kResizeBilinear); - MS_LOG(INFO) << "testResizeBilinear end."; -}