forked from mindspore-Ecosystem/mindspore
!4314 [MD] remove defaults used in binding code, and remove bilinear resize op
Merge pull request !4314 from nhussain/clean_up_bindings
This commit is contained in:
commit
9a3baf4f6c
|
@ -32,45 +32,37 @@ namespace mindspore {
|
|||
namespace dataset {
|
||||
|
||||
PYBIND_REGISTER(ConcatenateOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<ConcatenateOp, TensorOp, std::shared_ptr<ConcatenateOp>>(
|
||||
*m, "ConcatenateOp", "Tensor operation concatenate tensors.")
|
||||
.def(py::init<int8_t, std::shared_ptr<Tensor>, std::shared_ptr<Tensor>>(), py::arg("axis"),
|
||||
py::arg("prepend").none(true), py::arg("append").none(true));
|
||||
(void)py::class_<ConcatenateOp, TensorOp, std::shared_ptr<ConcatenateOp>>(*m, "ConcatenateOp")
|
||||
.def(py::init<int8_t, std::shared_ptr<Tensor>, std::shared_ptr<Tensor>>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(DuplicateOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<DuplicateOp, TensorOp, std::shared_ptr<DuplicateOp>>(*m, "DuplicateOp",
|
||||
"Duplicate tensor.")
|
||||
.def(py::init<>());
|
||||
}));
|
||||
PYBIND_REGISTER(
|
||||
DuplicateOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<DuplicateOp, TensorOp, std::shared_ptr<DuplicateOp>>(*m, "DuplicateOp").def(py::init<>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(FillOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<FillOp, TensorOp, std::shared_ptr<FillOp>>(
|
||||
*m, "FillOp", "Tensor operation to return tensor filled with same value as input fill value.")
|
||||
.def(py::init<std::shared_ptr<Tensor>>());
|
||||
}));
|
||||
PYBIND_REGISTER(
|
||||
FillOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<FillOp, TensorOp, std::shared_ptr<FillOp>>(*m, "FillOp").def(py::init<std::shared_ptr<Tensor>>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(MaskOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<MaskOp, TensorOp, std::shared_ptr<MaskOp>>(
|
||||
*m, "MaskOp", "Tensor mask operation using relational comparator")
|
||||
(void)py::class_<MaskOp, TensorOp, std::shared_ptr<MaskOp>>(*m, "MaskOp")
|
||||
.def(py::init<RelationalOp, std::shared_ptr<Tensor>, DataType>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(OneHotOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<OneHotOp, TensorOp, std::shared_ptr<OneHotOp>>(
|
||||
*m, "OneHotOp", "Tensor operation to apply one hot encoding. Takes number of classes.")
|
||||
.def(py::init<int32_t>());
|
||||
}));
|
||||
PYBIND_REGISTER(
|
||||
OneHotOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<OneHotOp, TensorOp, std::shared_ptr<OneHotOp>>(*m, "OneHotOp").def(py::init<int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(PadEndOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<PadEndOp, TensorOp, std::shared_ptr<PadEndOp>>(
|
||||
*m, "PadEndOp", "Tensor operation to pad end of tensor with a pad value.")
|
||||
(void)py::class_<PadEndOp, TensorOp, std::shared_ptr<PadEndOp>>(*m, "PadEndOp")
|
||||
.def(py::init<TensorShape, std::shared_ptr<Tensor>>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(SliceOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<SliceOp, TensorOp, std::shared_ptr<SliceOp>>(*m, "SliceOp",
|
||||
"Tensor slice operation.")
|
||||
(void)py::class_<SliceOp, TensorOp, std::shared_ptr<SliceOp>>(*m, "SliceOp")
|
||||
.def(py::init<bool>())
|
||||
.def(py::init([](const py::list &py_list) {
|
||||
std::vector<dsize_t> 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_<ToFloat16Op, TensorOp, std::shared_ptr<ToFloat16Op>>(
|
||||
*m, "ToFloat16Op", py::dynamic_attr(),
|
||||
"Tensor operator to type cast float32 data to a float16 type.")
|
||||
(void)py::class_<ToFloat16Op, TensorOp, std::shared_ptr<ToFloat16Op>>(*m, "ToFloat16Op",
|
||||
py::dynamic_attr())
|
||||
.def(py::init<>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(TypeCastOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<TypeCastOp, TensorOp, std::shared_ptr<TypeCastOp>>(
|
||||
*m, "TypeCastOp", "Tensor operator to type cast data to a specified type.")
|
||||
.def(py::init<DataType>(), py::arg("data_type"))
|
||||
.def(py::init<std::string>(), py::arg("data_type"));
|
||||
(void)py::class_<TypeCastOp, TensorOp, std::shared_ptr<TypeCastOp>>(*m, "TypeCastOp")
|
||||
.def(py::init<DataType>())
|
||||
.def(py::init<std::string>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RelationalOp, 0, ([](const py::module *m) {
|
||||
|
|
|
@ -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_<AutoContrastOp, TensorOp, std::shared_ptr<AutoContrastOp>>(
|
||||
*m, "AutoContrastOp", "Tensor operation to apply autocontrast on an image.")
|
||||
.def(py::init<float, std::vector<uint32_t>>(), py::arg("cutoff") = AutoContrastOp::kCutOff,
|
||||
py::arg("ignore") = AutoContrastOp::kIgnore);
|
||||
(void)py::class_<AutoContrastOp, TensorOp, std::shared_ptr<AutoContrastOp>>(*m, "AutoContrastOp")
|
||||
.def(py::init<float, std::vector<uint32_t>>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(NormalizeOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<NormalizeOp, TensorOp, std::shared_ptr<NormalizeOp>>(
|
||||
*m, "NormalizeOp", "Tensor operation to normalize an image. Takes mean and std.")
|
||||
.def(py::init<float, float, float, float, float, float>(), py::arg("meanR"), py::arg("meanG"),
|
||||
py::arg("meanB"), py::arg("stdR"), py::arg("stdG"), py::arg("stdB"));
|
||||
(void)py::class_<NormalizeOp, TensorOp, std::shared_ptr<NormalizeOp>>(*m, "NormalizeOp")
|
||||
.def(py::init<float, float, float, float, float, float>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(EqualizeOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<EqualizeOp, TensorOp, std::shared_ptr<EqualizeOp>>(
|
||||
*m, "EqualizeOp", "Tensor operation to apply histogram equalization on images.")
|
||||
.def(py::init<>());
|
||||
}));
|
||||
PYBIND_REGISTER(
|
||||
EqualizeOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<EqualizeOp, TensorOp, std::shared_ptr<EqualizeOp>>(*m, "EqualizeOp").def(py::init<>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(InvertOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<InvertOp, TensorOp, std::shared_ptr<InvertOp>>(
|
||||
*m, "InvertOp", "Tensor operation to apply invert on RGB images.")
|
||||
.def(py::init<>());
|
||||
(void)py::class_<InvertOp, TensorOp, std::shared_ptr<InvertOp>>(*m, "InvertOp").def(py::init<>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RescaleOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RescaleOp, TensorOp, std::shared_ptr<RescaleOp>>(
|
||||
*m, "RescaleOp", "Tensor operation to rescale an image. Takes scale and shift.")
|
||||
.def(py::init<float, float>(), py::arg("rescale"), py::arg("shift"));
|
||||
}));
|
||||
PYBIND_REGISTER(
|
||||
RescaleOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RescaleOp, TensorOp, std::shared_ptr<RescaleOp>>(*m, "RescaleOp").def(py::init<float, float>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(CenterCropOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<CenterCropOp, TensorOp, std::shared_ptr<CenterCropOp>>(
|
||||
*m, "CenterCropOp",
|
||||
"Tensor operation to crop and image in the middle. Takes height and width (optional)")
|
||||
.def(py::init<int32_t, int32_t>(), py::arg("height"), py::arg("width") = CenterCropOp::kDefWidth);
|
||||
.def(py::init<int32_t, int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(MixUpBatchOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<MixUpBatchOp, TensorOp, std::shared_ptr<MixUpBatchOp>>(
|
||||
*m, "MixUpBatchOp", "Tensor operation to mixup a batch of images")
|
||||
.def(py::init<float>(), py::arg("alpha"));
|
||||
}));
|
||||
PYBIND_REGISTER(
|
||||
MixUpBatchOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<MixUpBatchOp, TensorOp, std::shared_ptr<MixUpBatchOp>>(*m, "MixUpBatchOp").def(py::init<float>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(CutMixBatchOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<CutMixBatchOp, TensorOp, std::shared_ptr<CutMixBatchOp>>(
|
||||
*m, "CutMixBatchOp", "Tensor operation to cutmix a batch of images")
|
||||
.def(py::init<ImageBatchFormat, float, float>(), py::arg("image_batch_format"), py::arg("alpha"),
|
||||
py::arg("prob"));
|
||||
.def(py::init<ImageBatchFormat, float, float>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(ResizeOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<ResizeOp, TensorOp, std::shared_ptr<ResizeOp>>(
|
||||
*m, "ResizeOp", "Tensor operation to resize an image. Takes height, width and mode")
|
||||
.def(py::init<int32_t, int32_t, InterpolationMode>(), py::arg("targetHeight"),
|
||||
py::arg("targetWidth") = ResizeOp::kDefWidth,
|
||||
py::arg("interpolation") = ResizeOp::kDefInterpolation);
|
||||
(void)py::class_<ResizeOp, TensorOp, std::shared_ptr<ResizeOp>>(*m, "ResizeOp")
|
||||
.def(py::init<int32_t, int32_t, InterpolationMode>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(ResizeWithBBoxOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<ResizeWithBBoxOp, TensorOp, std::shared_ptr<ResizeWithBBoxOp>>(
|
||||
*m, "ResizeWithBBoxOp", "Tensor operation to resize an image. Takes height, width and mode.")
|
||||
.def(py::init<int32_t, int32_t, InterpolationMode>(), py::arg("targetHeight"),
|
||||
py::arg("targetWidth") = ResizeWithBBoxOp::kDefWidth,
|
||||
py::arg("interpolation") = ResizeWithBBoxOp::kDefInterpolation);
|
||||
(void)py::class_<ResizeWithBBoxOp, TensorOp, std::shared_ptr<ResizeWithBBoxOp>>(*m,
|
||||
"ResizeWithBBoxOp")
|
||||
.def(py::init<int32_t, int32_t, InterpolationMode>());
|
||||
}));
|
||||
|
||||
//####
|
||||
PYBIND_REGISTER(RandomAffineOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomAffineOp, TensorOp, std::shared_ptr<RandomAffineOp>>(
|
||||
*m, "RandomAffineOp", "Tensor operation to apply random affine transformations on an image.")
|
||||
.def(py::init<std::vector<float_t>, std::vector<float_t>, std::vector<float_t>,
|
||||
std::vector<float_t>, InterpolationMode, std::vector<uint8_t>>(),
|
||||
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<float_t>, InterpolationMode, std::vector<uint8_t>>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomResizeWithBBoxOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomResizeWithBBoxOp, TensorOp, std::shared_ptr<RandomResizeWithBBoxOp>>(
|
||||
*m, "RandomResizeWithBBoxOp")
|
||||
.def(py::init<int32_t, int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomPosterizeOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomPosterizeOp, TensorOp, std::shared_ptr<RandomPosterizeOp>>(
|
||||
*m, "RandomPosterizeOp", "Tensor operation to apply random posterize operation on an image.")
|
||||
.def(py::init<uint8_t, uint8_t>(), py::arg("min_bit") = RandomPosterizeOp::kMinBit,
|
||||
py::arg("max_bit") = RandomPosterizeOp::kMaxBit);
|
||||
(void)py::class_<RandomPosterizeOp, TensorOp, std::shared_ptr<RandomPosterizeOp>>(*m,
|
||||
"RandomPosterizeOp")
|
||||
.def(py::init<uint8_t, uint8_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(
|
||||
RandomResizeWithBBoxOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomResizeWithBBoxOp, TensorOp, std::shared_ptr<RandomResizeWithBBoxOp>>(
|
||||
*m, "RandomResizeWithBBoxOp",
|
||||
"Tensor operation to resize an image using a randomly selected interpolation. Takes height and width.")
|
||||
.def(py::init<int32_t, int32_t>(), py::arg("targetHeight"),
|
||||
py::arg("targetWidth") = RandomResizeWithBBoxOp::kDefTargetWidth);
|
||||
}));
|
||||
PYBIND_REGISTER(UniformAugOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<UniformAugOp, TensorOp, std::shared_ptr<UniformAugOp>>(
|
||||
*m, "UniformAugOp", "Tensor operation to apply random augmentation(s).")
|
||||
.def(py::init<std::vector<std::shared_ptr<TensorOp>>, int32_t>(), py::arg("transforms"),
|
||||
py::arg("NumOps") = UniformAugOp::kDefNumOps);
|
||||
(void)py::class_<UniformAugOp, TensorOp, std::shared_ptr<UniformAugOp>>(*m, "UniformAugOp")
|
||||
.def(py::init<std::vector<std::shared_ptr<TensorOp>>, int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(BoundingBoxAugmentOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<BoundingBoxAugmentOp, TensorOp, std::shared_ptr<BoundingBoxAugmentOp>>(
|
||||
*m, "BoundingBoxAugmentOp",
|
||||
"Tensor operation to apply a transformation on a random choice of bounding boxes.")
|
||||
.def(py::init<std::shared_ptr<TensorOp>, float>(), py::arg("transform"),
|
||||
py::arg("ratio") = BoundingBoxAugmentOp::kDefRatio);
|
||||
}));
|
||||
PYBIND_REGISTER(ResizeBilinearOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<ResizeBilinearOp, TensorOp, std::shared_ptr<ResizeBilinearOp>>(
|
||||
*m, "ResizeBilinearOp",
|
||||
"Tensor operation to resize an image using "
|
||||
"Bilinear mode. Takes height and width.")
|
||||
.def(py::init<int32_t, int32_t>(), py::arg("targetHeight"),
|
||||
py::arg("targetWidth") = ResizeBilinearOp::kDefWidth);
|
||||
*m, "BoundingBoxAugmentOp")
|
||||
.def(py::init<std::shared_ptr<TensorOp>, float>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(DecodeOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<DecodeOp, TensorOp, std::shared_ptr<DecodeOp>>(
|
||||
*m, "DecodeOp", "Tensor operation to decode a jpg image")
|
||||
(void)py::class_<DecodeOp, TensorOp, std::shared_ptr<DecodeOp>>(*m, "DecodeOp")
|
||||
.def(py::init<>())
|
||||
.def(py::init<bool>(), py::arg("rgb_format") = DecodeOp::kDefRgbFormat);
|
||||
.def(py::init<bool>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomHorizontalFlipOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomHorizontalFlipOp, TensorOp, std::shared_ptr<RandomHorizontalFlipOp>>(
|
||||
*m, "RandomHorizontalFlipOp", "Tensor operation to randomly flip an image horizontally.")
|
||||
.def(py::init<float>(), py::arg("probability") = RandomHorizontalFlipOp::kDefProbability);
|
||||
*m, "RandomHorizontalFlipOp")
|
||||
.def(py::init<float>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(
|
||||
RandomHorizontalFlipWithBBoxOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomHorizontalFlipWithBBoxOp, TensorOp, std::shared_ptr<RandomHorizontalFlipWithBBoxOp>>(
|
||||
*m, "RandomHorizontalFlipWithBBoxOp",
|
||||
"Tensor operation to randomly flip an image horizontally, while flipping bounding boxes.")
|
||||
.def(py::init<float>(), py::arg("probability") = RandomHorizontalFlipWithBBoxOp::kDefProbability);
|
||||
*m, "RandomHorizontalFlipWithBBoxOp")
|
||||
.def(py::init<float>());
|
||||
}));
|
||||
PYBIND_REGISTER(RandomVerticalFlipOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomVerticalFlipOp, TensorOp, std::shared_ptr<RandomVerticalFlipOp>>(
|
||||
*m, "RandomVerticalFlipOp", "Tensor operation to randomly flip an image vertically.")
|
||||
.def(py::init<float>(), py::arg("probability") = RandomVerticalFlipOp::kDefProbability);
|
||||
*m, "RandomVerticalFlipOp")
|
||||
.def(py::init<float>());
|
||||
}));
|
||||
PYBIND_REGISTER(RandomVerticalFlipWithBBoxOp, 1, ([](const py::module *m) {
|
||||
(void)
|
||||
py::class_<RandomVerticalFlipWithBBoxOp, TensorOp, std::shared_ptr<RandomVerticalFlipWithBBoxOp>>(
|
||||
*m, "RandomVerticalFlipWithBBoxOp",
|
||||
"Tensor operation to randomly flip an image vertically"
|
||||
" and adjust bounding boxes.")
|
||||
.def(py::init<float>(), py::arg("probability") = RandomVerticalFlipWithBBoxOp::kDefProbability);
|
||||
*m, "RandomVerticalFlipWithBBoxOp")
|
||||
.def(py::init<float>());
|
||||
}));
|
||||
PYBIND_REGISTER(
|
||||
RandomCropOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomCropOp, TensorOp, std::shared_ptr<RandomCropOp>>(*m, "RandomCropOp",
|
||||
"Gives random crop of specified size "
|
||||
"Takes crop size")
|
||||
(void)py::class_<RandomCropOp, TensorOp, std::shared_ptr<RandomCropOp>>(*m, "RandomCropOp")
|
||||
.def(
|
||||
py::init<int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, BorderType, bool, uint8_t, uint8_t, uint8_t>(),
|
||||
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<int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, BorderType, bool, uint8_t, uint8_t, uint8_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(
|
||||
HwcToChwOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<HwcToChwOp, TensorOp, std::shared_ptr<HwcToChwOp>>(*m, "ChannelSwapOp").def(py::init<>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(
|
||||
RandomCropWithBBoxOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomCropWithBBoxOp, TensorOp, std::shared_ptr<RandomCropWithBBoxOp>>(
|
||||
*m, "RandomCropWithBBoxOp",
|
||||
"Gives random crop of given "
|
||||
"size + adjusts bboxes "
|
||||
"Takes crop size")
|
||||
(void)py::class_<RandomCropWithBBoxOp, TensorOp, std::shared_ptr<RandomCropWithBBoxOp>>(*m, "RandomCropWithBBoxOp")
|
||||
.def(
|
||||
py::init<int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, BorderType, bool, uint8_t, uint8_t, uint8_t>(),
|
||||
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_<CutOutOp, TensorOp, std::shared_ptr<CutOutOp>>(
|
||||
*m, "CutOutOp",
|
||||
"Tensor operation to randomly erase a portion of the image. Takes height and width.")
|
||||
.def(py::init<int32_t, int32_t, int32_t, bool, uint8_t, uint8_t, uint8_t>(), 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<int32_t, int32_t, int32_t, bool, uint8_t, uint8_t, uint8_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(PadOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<PadOp, TensorOp, std::shared_ptr<PadOp>>(
|
||||
*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<int32_t, int32_t, int32_t, int32_t, BorderType, uint8_t, uint8_t, uint8_t>(),
|
||||
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_<PadOp, TensorOp, std::shared_ptr<PadOp>>(*m, "PadOp")
|
||||
.def(py::init<int32_t, int32_t, int32_t, int32_t, BorderType, uint8_t, uint8_t, uint8_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomCropDecodeResizeOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomCropDecodeResizeOp, TensorOp, std::shared_ptr<RandomCropDecodeResizeOp>>(
|
||||
*m, "RandomCropDecodeResizeOp", "equivalent to RandomCropAndResize but crops before decoding")
|
||||
.def(py::init<int32_t, int32_t, float, float, float, float, InterpolationMode, int32_t>(),
|
||||
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<int32_t, int32_t, float, float, float, float, InterpolationMode, int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(
|
||||
RandomResizeOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomResizeOp, TensorOp, std::shared_ptr<RandomResizeOp>>(
|
||||
*m, "RandomResizeOp",
|
||||
"Tensor operation to resize an image using a randomly selected interpolation. Takes height and width.")
|
||||
.def(py::init<int32_t, int32_t>(), py::arg("targetHeight"),
|
||||
py::arg("targetWidth") = RandomResizeOp::kDefTargetWidth);
|
||||
}));
|
||||
PYBIND_REGISTER(RandomResizeOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomResizeOp, TensorOp, std::shared_ptr<RandomResizeOp>>(*m, "RandomResizeOp")
|
||||
.def(py::init<int32_t, int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomColorOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomColorOp, TensorOp, std::shared_ptr<RandomColorOp>>(
|
||||
*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<float, float>(), py::arg("min"), py::arg("max"));
|
||||
(void)py::class_<RandomColorOp, TensorOp, std::shared_ptr<RandomColorOp>>(*m, "RandomColorOp")
|
||||
.def(py::init<float, float>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomColorAdjustOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomColorAdjustOp, TensorOp, std::shared_ptr<RandomColorAdjustOp>>(
|
||||
*m, "RandomColorAdjustOp",
|
||||
"Tensor operation to adjust an image's color randomly."
|
||||
"Takes range for brightness, contrast, saturation, hue and")
|
||||
.def(py::init<float, float, float, float, float, float, float, float>(),
|
||||
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<float, float, float, float, float, float, float, float>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomCropAndResizeWithBBoxOp, 1, ([](const py::module *m) {
|
||||
(void)
|
||||
py::class_<RandomCropAndResizeWithBBoxOp, TensorOp, std::shared_ptr<RandomCropAndResizeWithBBoxOp>>(
|
||||
*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<int32_t, int32_t, float, float, float, float, InterpolationMode, int32_t>(),
|
||||
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<int32_t, int32_t, float, float, float, float, InterpolationMode, int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomCropAndResizeOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomCropAndResizeOp, TensorOp, std::shared_ptr<RandomCropAndResizeOp>>(
|
||||
*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<int32_t, int32_t, float, float, float, float, InterpolationMode, int32_t>(),
|
||||
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<int32_t, int32_t, float, float, float, float, InterpolationMode, int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomRotationOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomRotationOp, TensorOp, std::shared_ptr<RandomRotationOp>>(
|
||||
*m, "RandomRotationOp",
|
||||
"Tensor operation to apply RandomRotation."
|
||||
"Takes a range for degrees and "
|
||||
"optional parameters for rotation center and image expand")
|
||||
.def(
|
||||
py::init<float, float, float, float, InterpolationMode, bool, uint8_t, uint8_t, uint8_t>(),
|
||||
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_<RandomRotationOp, TensorOp, std::shared_ptr<RandomRotationOp>>(*m,
|
||||
"RandomRotationOp")
|
||||
.def(py::init<float, float, float, float, InterpolationMode, bool, uint8_t, uint8_t, uint8_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomSharpnessOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RandomSharpnessOp, TensorOp, std::shared_ptr<RandomSharpnessOp>>(
|
||||
*m, "RandomSharpnessOp",
|
||||
"Tensor operation to apply RandomSharpness."
|
||||
"Takes a range for degrees")
|
||||
.def(py::init<float, float>(), py::arg("startDegree") = RandomSharpnessOp::kDefStartDegree,
|
||||
py::arg("endDegree") = RandomSharpnessOp::kDefEndDegree);
|
||||
(void)py::class_<RandomSharpnessOp, TensorOp, std::shared_ptr<RandomSharpnessOp>>(*m,
|
||||
"RandomSharpnessOp")
|
||||
.def(py::init<float, float>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomSelectSubpolicyOp, 1, ([](const py::module *m) {
|
||||
|
@ -400,23 +292,19 @@ PYBIND_REGISTER(RandomSelectSubpolicyOp, 1, ([](const py::module *m) {
|
|||
return std::make_shared<RandomSelectSubpolicyOp>(cpp_policy);
|
||||
}));
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(SoftDvppDecodeResizeJpegOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<SoftDvppDecodeResizeJpegOp, TensorOp, std::shared_ptr<SoftDvppDecodeResizeJpegOp>>(
|
||||
*m, "SoftDvppDecodeResizeJpegOp", "TensorOp to use soft dvpp decode and resize jpeg image.")
|
||||
.def(py::init<int32_t, int32_t>(), py::arg("targetHeight"), py::arg("targetWidth"));
|
||||
*m, "SoftDvppDecodeResizeJpegOp")
|
||||
.def(py::init<int32_t, int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(
|
||||
SoftDvppDecodeRandomCropResizeJpegOp, 1, ([](const py::module *m) {
|
||||
(void)
|
||||
py::class_<SoftDvppDecodeRandomCropResizeJpegOp, TensorOp, std::shared_ptr<SoftDvppDecodeRandomCropResizeJpegOp>>(
|
||||
*m, "SoftDvppDecodeRandomCropResizeJpegOp",
|
||||
"TensorOp to use soft dvpp decode, random crop and resize jepg image.")
|
||||
.def(py::init<int32_t, int32_t, float, float, float, float, int32_t>(), 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<int32_t, int32_t, float, float, float, float, int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RandomSolarizeOp, 1, ([](const py::module *m) {
|
||||
|
|
|
@ -46,73 +46,50 @@ namespace dataset {
|
|||
#ifdef ENABLE_ICU4C
|
||||
|
||||
PYBIND_REGISTER(BasicTokenizerOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<BasicTokenizerOp, TensorOp, std::shared_ptr<BasicTokenizerOp>>(
|
||||
*m, "BasicTokenizerOp", "Tokenize a scalar tensor of UTF-8 string by specific rules.")
|
||||
.def(py::init<const bool &, const bool &, const NormalizeForm &, const bool &, const bool &>(),
|
||||
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_<BasicTokenizerOp, TensorOp, std::shared_ptr<BasicTokenizerOp>>(*m,
|
||||
"BasicTokenizerOp")
|
||||
.def(py::init<const bool &, const bool &, const NormalizeForm &, const bool &, const bool &>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(WhitespaceTokenizerOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<WhitespaceTokenizerOp, TensorOp, std::shared_ptr<WhitespaceTokenizerOp>>(
|
||||
*m, "WhitespaceTokenizerOp", "Tokenize a scalar tensor of UTF-8 string on ICU defined whitespaces.")
|
||||
.def(py::init<const bool &>(), py::arg(" with_offsets ") = WhitespaceTokenizerOp::kDefWithOffsets);
|
||||
*m, "WhitespaceTokenizerOp")
|
||||
.def(py::init<const bool &>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(UnicodeScriptTokenizerOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<UnicodeScriptTokenizerOp, TensorOp, std::shared_ptr<UnicodeScriptTokenizerOp>>(
|
||||
*m, "UnicodeScriptTokenizerOp",
|
||||
"Tokenize a scalar tensor of UTF-8 string on Unicode script boundaries.")
|
||||
*m, "UnicodeScriptTokenizerOp")
|
||||
.def(py::init<>())
|
||||
.def(py::init<const bool &, const bool &>(),
|
||||
py::arg("keep_whitespace") = UnicodeScriptTokenizerOp::kDefKeepWhitespace,
|
||||
py::arg("with_offsets") = UnicodeScriptTokenizerOp::kDefWithOffsets);
|
||||
.def(py::init<const bool &, const bool &>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(CaseFoldOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<CaseFoldOp, TensorOp, std::shared_ptr<CaseFoldOp>>(
|
||||
*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_<CaseFoldOp, TensorOp, std::shared_ptr<CaseFoldOp>>(*m, "CaseFoldOp").def(py::init<>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(NormalizeUTF8Op, 1, ([](const py::module *m) {
|
||||
(void)py::class_<NormalizeUTF8Op, TensorOp, std::shared_ptr<NormalizeUTF8Op>>(
|
||||
*m, "NormalizeUTF8Op", "Apply normalize operation on utf-8 string tensor.")
|
||||
(void)py::class_<NormalizeUTF8Op, TensorOp, std::shared_ptr<NormalizeUTF8Op>>(*m, "NormalizeUTF8Op")
|
||||
.def(py::init<>())
|
||||
.def(py::init<NormalizeForm>(), py::arg("normalize_form") = NormalizeUTF8Op::kDefNormalizeForm);
|
||||
.def(py::init<NormalizeForm>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RegexReplaceOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RegexReplaceOp, TensorOp, std::shared_ptr<RegexReplaceOp>>(
|
||||
*m, "RegexReplaceOp",
|
||||
"Replace utf-8 string tensor with 'replace' according to regular expression 'pattern'.")
|
||||
.def(py::init<const std::string &, const std::string &, bool>(), py::arg("pattern"),
|
||||
py::arg("replace"), py::arg("replace_all"));
|
||||
(void)py::class_<RegexReplaceOp, TensorOp, std::shared_ptr<RegexReplaceOp>>(*m, "RegexReplaceOp")
|
||||
.def(py::init<const std::string &, const std::string &, bool>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(RegexTokenizerOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<RegexTokenizerOp, TensorOp, std::shared_ptr<RegexTokenizerOp>>(
|
||||
*m, "RegexTokenizerOp", "Tokenize a scalar tensor of UTF-8 string by regex expression pattern.")
|
||||
.def(py::init<const std::string &, const std::string &, const bool &>(), py::arg("delim_pattern"),
|
||||
py::arg("keep_delim_pattern"), py::arg("with_offsets") = RegexTokenizerOp::kDefWithOffsets);
|
||||
(void)py::class_<RegexTokenizerOp, TensorOp, std::shared_ptr<RegexTokenizerOp>>(*m,
|
||||
"RegexTokenizerOp")
|
||||
.def(py::init<const std::string &, const std::string &, const bool &>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(BertTokenizerOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<BertTokenizerOp, TensorOp, std::shared_ptr<BertTokenizerOp>>(
|
||||
*m, "BertTokenizerOp", "Tokenizer used for Bert text process.")
|
||||
(void)py::class_<BertTokenizerOp, TensorOp, std::shared_ptr<BertTokenizerOp>>(*m, "BertTokenizerOp")
|
||||
.def(py::init<const std::shared_ptr<Vocab> &, 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_<JiebaTokenizerOp, TensorOp, std::shared_ptr<JiebaTokenizerOp>>(
|
||||
*m, "JiebaTokenizerOp", "")
|
||||
.def(py::init<const std::string &, const std::string &, const JiebaMode &, const bool &>(),
|
||||
py::arg("hmm_path"), py::arg("mp_path"), py::arg("mode") = JiebaMode::kMix,
|
||||
py::arg("with_offsets") = JiebaTokenizerOp::kDefWithOffsets)
|
||||
(void)py::class_<JiebaTokenizerOp, TensorOp, std::shared_ptr<JiebaTokenizerOp>>(*m,
|
||||
"JiebaTokenizerOp")
|
||||
.def(py::init<const std::string &, const std::string &, const JiebaMode &, const bool &>())
|
||||
.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_<UnicodeCharTokenizerOp, TensorOp, std::shared_ptr<UnicodeCharTokenizerOp>>(
|
||||
*m, "UnicodeCharTokenizerOp", "Tokenize a scalar tensor of UTF-8 string to Unicode characters.")
|
||||
.def(py::init<const bool &>(), py::arg("with_offsets") = UnicodeCharTokenizerOp::kDefWithOffsets);
|
||||
*m, "UnicodeCharTokenizerOp")
|
||||
.def(py::init<const bool &>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(LookupOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<LookupOp, TensorOp, std::shared_ptr<LookupOp>>(
|
||||
*m, "LookupOp", "Tensor operation to LookUp each word.")
|
||||
(void)py::class_<LookupOp, TensorOp, std::shared_ptr<LookupOp>>(*m, "LookupOp")
|
||||
.def(py::init([](std::shared_ptr<Vocab> 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_<NgramOp, TensorOp, std::shared_ptr<NgramOp>>(*m, "NgramOp",
|
||||
"TensorOp performs ngram mapping.")
|
||||
(void)py::class_<NgramOp, TensorOp, std::shared_ptr<NgramOp>>(*m, "NgramOp")
|
||||
.def(py::init<const std::vector<int32_t> &, 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_<WordpieceTokenizerOp, TensorOp, std::shared_ptr<WordpieceTokenizerOp>>(
|
||||
*m, "WordpieceTokenizerOp", "Tokenize scalar token or 1-D tokens to subword tokens.")
|
||||
.def(
|
||||
py::init<const std::shared_ptr<Vocab> &, 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_<WordpieceTokenizerOp, TensorOp, std::shared_ptr<WordpieceTokenizerOp>>(
|
||||
*m, "WordpieceTokenizerOp")
|
||||
.def(py::init<const std::shared_ptr<Vocab> &, const std::string &, const int &, const std::string &,
|
||||
const bool &>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(SlidingWindowOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<SlidingWindowOp, TensorOp, std::shared_ptr<SlidingWindowOp>>(
|
||||
*m, "SlidingWindowOp", "TensorOp to apply sliding window to a 1-D Tensor.")
|
||||
.def(py::init<uint32_t, int32_t>(), py::arg("width"), py::arg("axis"));
|
||||
(void)py::class_<SlidingWindowOp, TensorOp, std::shared_ptr<SlidingWindowOp>>(*m, "SlidingWindowOp")
|
||||
.def(py::init<uint32_t, int32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(
|
||||
SentencePieceTokenizerOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<SentencePieceTokenizerOp, TensorOp, std::shared_ptr<SentencePieceTokenizerOp>>(
|
||||
*m, "SentencePieceTokenizerOp", "Tokenize scalar token or 1-D tokens to tokens by sentence piece.")
|
||||
*m, "SentencePieceTokenizerOp")
|
||||
.def(
|
||||
py::init<std::shared_ptr<SentencePieceVocab> &, const SPieceTokenizerLoadType, const SPieceTokenizerOutType>(),
|
||||
py::arg("vocab"), py::arg("load_type") = SPieceTokenizerLoadType::kModel,
|
||||
py::arg("out_type") = SPieceTokenizerOutType::kString)
|
||||
py::init<std::shared_ptr<SentencePieceVocab> &, const SPieceTokenizerLoadType, const SPieceTokenizerOutType>())
|
||||
.def(py::init<const std::string &, const std::string &, const SPieceTokenizerLoadType,
|
||||
const SPieceTokenizerOutType>(),
|
||||
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_<ToNumberOp, TensorOp, std::shared_ptr<ToNumberOp>>(
|
||||
*m, "ToNumberOp", "TensorOp to convert strings to numbers.")
|
||||
.def(py::init<DataType>(), py::arg("data_type"))
|
||||
.def(py::init<std::string>(), py::arg("data_type"));
|
||||
(void)py::class_<ToNumberOp, TensorOp, std::shared_ptr<ToNumberOp>>(*m, "ToNumberOp")
|
||||
.def(py::init<DataType>())
|
||||
.def(py::init<std::string>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(TruncateSequencePairOp, 1, ([](const py::module *m) {
|
||||
(void)py::class_<TruncateSequencePairOp, TensorOp, std::shared_ptr<TruncateSequencePairOp>>(
|
||||
*m, "TruncateSequencePairOp", "Tensor operation to truncate two tensors to a max_length")
|
||||
*m, "TruncateSequencePairOp")
|
||||
.def(py::init<int64_t>());
|
||||
}));
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ PYBIND_REGISTER(
|
|||
ShardSample, 0, ([](const py::module *m) {
|
||||
(void)py::class_<mindrecord::ShardSample, mindrecord::ShardOperator, std::shared_ptr<mindrecord::ShardSample>>(
|
||||
*m, "MindrecordSubsetRandomSampler")
|
||||
.def(py::init<std::vector<int64_t>, uint32_t>(), py::arg("indices"), py::arg("seed") = GetSeed());
|
||||
.def(py::init<std::vector<int64_t>, uint32_t>());
|
||||
}));
|
||||
|
||||
PYBIND_REGISTER(ShardSequentialSample, 0, ([](const py::module *m) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <random>
|
||||
|
||||
#include "minddata/dataset/util/status.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace dataset {
|
||||
const int32_t ResizeBilinearOp::kDefWidth = 0;
|
||||
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<Tensor> output_tensor;
|
||||
// Resizing
|
||||
std::unique_ptr<ResizeBilinearOp> 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.";
|
||||
}
|
Loading…
Reference in New Issue