dataset: Create C++ API classes for vision transform ops
Review rework Add overloaded API Map function Overload Execute, update st test_de.cc and enhance ut execute_test.cc; More TensorTransform support for BoundingBoxAugment and UniformAug Execute support for auto case; UT updates Rebase updates, including fix CI Ascend compilations test_de.cc - comment out dvpp tests Rebase updates Added back testcase and constructor Added back constructor added missing macro Fixed Macro removed decode
This commit is contained in:
parent
98f6d78778
commit
3fc204e3bc
|
@ -33,6 +33,7 @@
|
|||
namespace mindspore {
|
||||
namespace dataset {
|
||||
|
||||
// FIXME - Temporarily overload Execute to support both TensorOperation and TensorTransform
|
||||
Execute::Execute(std::shared_ptr<TensorOperation> op, std::string deviceType) {
|
||||
ops_.emplace_back(std::move(op));
|
||||
device_type_ = deviceType;
|
||||
|
@ -49,6 +50,63 @@ Execute::Execute(std::shared_ptr<TensorOperation> op, std::string deviceType) {
|
|||
#endif
|
||||
}
|
||||
|
||||
Execute::Execute(std::shared_ptr<TensorTransform> op, std::string deviceType) {
|
||||
// Convert op from TensorTransform to TensorOperation
|
||||
std::shared_ptr<TensorOperation> operation = op->Parse();
|
||||
ops_.emplace_back(std::move(operation));
|
||||
device_type_ = deviceType;
|
||||
MS_LOG(INFO) << "Running Device: " << device_type_;
|
||||
#ifdef ENABLE_ACL
|
||||
if (device_type_ == "Ascend310") {
|
||||
device_resource_ = std::make_shared<AscendResource>();
|
||||
Status rc = device_resource_->InitResource();
|
||||
if (!rc.IsOk()) {
|
||||
device_resource_ = nullptr;
|
||||
MS_LOG(ERROR) << "Initialize Ascend310 resource fail";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
Execute::Execute(TensorTransform op, std::string deviceType) {
|
||||
// Convert op from TensorTransform to TensorOperation
|
||||
std::shared_ptr<TensorOperation> operation = op.Parse();
|
||||
ops_.emplace_back(std::move(operation));
|
||||
device_type_ = deviceType;
|
||||
MS_LOG(INFO) << "Running Device: " << device_type_;
|
||||
#ifdef ENABLE_ACL
|
||||
if (device_type_ == "Ascend310") {
|
||||
device_resource_ = std::make_shared<AscendResource>();
|
||||
Status rc = device_resource_->InitResource();
|
||||
if (!rc.IsOk()) {
|
||||
device_resource_ = nullptr;
|
||||
MS_LOG(ERROR) << "Initialize Ascend310 resource fail";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
// Execute function for the example case: auto decode(new vision::Decode());
|
||||
Execute::Execute(TensorTransform *op, std::string deviceType) {
|
||||
// Convert op from TensorTransform to TensorOperation
|
||||
std::shared_ptr<TensorOperation> operation = op->Parse();
|
||||
ops_.emplace_back(std::move(operation));
|
||||
device_type_ = deviceType;
|
||||
MS_LOG(INFO) << "Running Device: " << device_type_;
|
||||
#ifdef ENABLE_ACL
|
||||
if (device_type_ == "Ascend310") {
|
||||
device_resource_ = std::make_shared<AscendResource>();
|
||||
Status rc = device_resource_->InitResource();
|
||||
if (!rc.IsOk()) {
|
||||
device_resource_ = nullptr;
|
||||
MS_LOG(ERROR) << "Initialize Ascend310 resource fail";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Execute::Execute(std::vector<std::shared_ptr<TensorOperation>> ops, std::string deviceType)
|
||||
: ops_(std::move(ops)), device_type_(deviceType) {
|
||||
MS_LOG(INFO) << "Running Device: " << device_type_;
|
||||
|
@ -64,6 +122,64 @@ Execute::Execute(std::vector<std::shared_ptr<TensorOperation>> ops, std::string
|
|||
#endif
|
||||
}
|
||||
|
||||
Execute::Execute(std::vector<std::shared_ptr<TensorTransform>> ops, std::string deviceType) {
|
||||
// Convert ops from TensorTransform to TensorOperation
|
||||
(void)std::transform(
|
||||
ops.begin(), ops.end(), std::back_inserter(ops_),
|
||||
[](std::shared_ptr<TensorTransform> operation) -> std::shared_ptr<TensorOperation> { return operation->Parse(); });
|
||||
device_type_ = deviceType;
|
||||
MS_LOG(INFO) << "Running Device: " << device_type_;
|
||||
#ifdef ENABLE_ACL
|
||||
if (device_type_ == "Ascend310") {
|
||||
device_resource_ = std::make_shared<AscendResource>();
|
||||
Status rc = device_resource_->InitResource();
|
||||
if (!rc.IsOk()) {
|
||||
device_resource_ = nullptr;
|
||||
MS_LOG(ERROR) << "Initialize Ascend310 resource fail";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Execute::Execute(const std::vector<std::reference_wrapper<TensorTransform>> ops, std::string deviceType) {
|
||||
// Convert ops from TensorTransform to TensorOperation
|
||||
(void)std::transform(
|
||||
ops.begin(), ops.end(), std::back_inserter(ops_),
|
||||
[](TensorTransform &operation) -> std::shared_ptr<TensorOperation> { return operation.Parse(); });
|
||||
device_type_ = deviceType;
|
||||
MS_LOG(INFO) << "Running Device: " << device_type_;
|
||||
#ifdef ENABLE_ACL
|
||||
if (device_type_ == "Ascend310") {
|
||||
device_resource_ = std::make_shared<AscendResource>();
|
||||
Status rc = device_resource_->InitResource();
|
||||
if (!rc.IsOk()) {
|
||||
device_resource_ = nullptr;
|
||||
MS_LOG(ERROR) << "Initialize Ascend310 resource fail";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Execute function for the example vector case: auto decode(new vision::Decode());
|
||||
Execute::Execute(std::vector<TensorTransform *> ops, std::string deviceType) {
|
||||
// Convert ops from TensorTransform to TensorOperation
|
||||
(void)std::transform(
|
||||
ops.begin(), ops.end(), std::back_inserter(ops_),
|
||||
[](TensorTransform *operation) -> std::shared_ptr<TensorOperation> { return operation->Parse(); });
|
||||
device_type_ = deviceType;
|
||||
MS_LOG(INFO) << "Running Device: " << device_type_;
|
||||
#ifdef ENABLE_ACL
|
||||
if (device_type_ == "Ascend310") {
|
||||
device_resource_ = std::make_shared<AscendResource>();
|
||||
Status rc = device_resource_->InitResource();
|
||||
if (!rc.IsOk()) {
|
||||
device_resource_ = nullptr;
|
||||
MS_LOG(ERROR) << "Initialize Ascend310 resource fail";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Execute::~Execute() {
|
||||
#ifdef ENABLE_ACL
|
||||
if (device_type_ == "Ascend310") {
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
|
||||
#include "minddata/dataset/include/vision.h"
|
||||
#ifdef ENABLE_ACL
|
||||
#include "minddata/dataset/include/vision_ascend.h"
|
||||
#endif
|
||||
|
||||
#include "minddata/dataset/include/transforms.h"
|
||||
#include "minddata/dataset/kernels/ir/vision/vision_ir.h"
|
||||
|
@ -25,19 +28,8 @@
|
|||
#include "minddata/dataset/kernels/ir/validators.h"
|
||||
|
||||
// Kernel image headers (in alphabetical order)
|
||||
#ifndef ENABLE_ANDROID
|
||||
#include "minddata/dataset/kernels/image/auto_contrast_op.h"
|
||||
#include "minddata/dataset/kernels/image/bounding_box_augment_op.h"
|
||||
#endif
|
||||
#include "minddata/dataset/kernels/image/center_crop_op.h"
|
||||
#include "minddata/dataset/kernels/image/crop_op.h"
|
||||
#ifndef ENABLE_ANDROID
|
||||
#include "minddata/dataset/kernels/image/cutmix_batch_op.h"
|
||||
#include "minddata/dataset/kernels/image/cut_out_op.h"
|
||||
#endif
|
||||
#include "minddata/dataset/kernels/image/decode_op.h"
|
||||
// FIXME - Delete these dvpp include header when dvpp TensorOperation moved to IR level
|
||||
#ifdef ENABLE_ACL
|
||||
#include "minddata/dataset/include/vision_ascend.h"
|
||||
#include "minddata/dataset/kernels/image/dvpp/dvpp_crop_jpeg_op.h"
|
||||
#include "minddata/dataset/kernels/image/dvpp/dvpp_decode_resize_jpeg_op.h"
|
||||
#include "minddata/dataset/kernels/image/dvpp/dvpp_decode_resize_crop_jpeg_op.h"
|
||||
|
@ -45,48 +37,6 @@
|
|||
#include "minddata/dataset/kernels/image/dvpp/dvpp_decode_png_op.h"
|
||||
#include "minddata/dataset/kernels/image/dvpp/dvpp_resize_jpeg_op.h"
|
||||
#endif
|
||||
#ifndef ENABLE_ANDROID
|
||||
#include "minddata/dataset/kernels/image/equalize_op.h"
|
||||
#include "minddata/dataset/kernels/image/hwc_to_chw_op.h"
|
||||
#include "minddata/dataset/kernels/image/invert_op.h"
|
||||
#include "minddata/dataset/kernels/image/mixup_batch_op.h"
|
||||
#endif
|
||||
#include "minddata/dataset/kernels/image/normalize_op.h"
|
||||
#include "minddata/dataset/kernels/image/normalize_pad_op.h"
|
||||
#ifndef ENABLE_ANDROID
|
||||
#include "minddata/dataset/kernels/image/pad_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_affine_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_color_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_color_adjust_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_crop_and_resize_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_crop_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_crop_decode_resize_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_crop_with_bbox_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_crop_and_resize_with_bbox_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_horizontal_flip_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_horizontal_flip_with_bbox_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_posterize_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_resize_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_resize_with_bbox_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_rotation_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_select_subpolicy_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_sharpness_op.h"
|
||||
#include "minddata/dataset/kernels/image/random_solarize_op.h"
|
||||
#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"
|
||||
#endif
|
||||
#include "minddata/dataset/kernels/image/resize_op.h"
|
||||
#ifndef ENABLE_ANDROID
|
||||
#include "minddata/dataset/kernels/image/resize_with_bbox_op.h"
|
||||
#include "minddata/dataset/kernels/image/rgba_to_bgr_op.h"
|
||||
#include "minddata/dataset/kernels/image/rgba_to_rgb_op.h"
|
||||
#include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.h"
|
||||
#include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.h"
|
||||
#include "minddata/dataset/kernels/image/swap_red_blue_op.h"
|
||||
#include "minddata/dataset/kernels/image/uniform_aug_op.h"
|
||||
#endif
|
||||
#include "minddata/dataset/kernels/image/rotate_op.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace dataset {
|
||||
|
@ -97,57 +47,54 @@ namespace vision {
|
|||
// FUNCTIONS TO CREATE VISION TRANSFORM OPERATIONS
|
||||
// (In alphabetical order)
|
||||
|
||||
// Function to create AutoContrastOperation.
|
||||
std::shared_ptr<AutoContrastOperation> AutoContrast(float cutoff, std::vector<uint32_t> ignore) {
|
||||
auto op = std::make_shared<AutoContrastOperation>(cutoff, ignore);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// AutoContrast Transform Operation.
|
||||
AutoContrast::AutoContrast(float cutoff, std::vector<uint32_t> ignore) : cutoff_(cutoff), ignore_(ignore) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> AutoContrast::Parse() {
|
||||
return std::make_shared<AutoContrastOperation>(cutoff_, ignore_);
|
||||
}
|
||||
|
||||
// Function to create BoundingBoxAugmentOperation.
|
||||
std::shared_ptr<BoundingBoxAugmentOperation> BoundingBoxAugment(std::shared_ptr<TensorOperation> transform,
|
||||
float ratio) {
|
||||
auto op = std::make_shared<BoundingBoxAugmentOperation>(transform, ratio);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// BoundingBoxAugment Transform Operation.
|
||||
BoundingBoxAugment::BoundingBoxAugment(std::shared_ptr<TensorTransform> transform, float ratio) {
|
||||
// Convert transform from TensorTransform to TensorOperation
|
||||
transform_ = transform->Parse();
|
||||
ratio_ = ratio;
|
||||
}
|
||||
|
||||
std::shared_ptr<TensorOperation> BoundingBoxAugment::Parse() {
|
||||
return std::make_shared<BoundingBoxAugmentOperation>(transform_, ratio_);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Function to create CenterCropOperation.
|
||||
std::shared_ptr<CenterCropOperation> CenterCrop(std::vector<int32_t> size) {
|
||||
auto op = std::make_shared<CenterCropOperation>(size);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
// CenterCrop Transform Operation.
|
||||
CenterCrop::CenterCrop(std::vector<int32_t> size) : size_(size) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> CenterCrop::Parse() { return std::make_shared<CenterCropOperation>(size_); }
|
||||
|
||||
// Crop Transform Operation.
|
||||
Crop::Crop(std::vector<int32_t> coordinates, std::vector<int32_t> size) : coordinates_(coordinates), size_(size) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> Crop::Parse() { return std::make_shared<CropOperation>(coordinates_, size_); }
|
||||
|
||||
// Function to create CropOperation.
|
||||
std::shared_ptr<CropOperation> Crop(std::vector<int32_t> coordinates, std::vector<int32_t> size) {
|
||||
auto op = std::make_shared<CropOperation>(coordinates, size);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
#ifndef ENABLE_ANDROID
|
||||
// Function to create CutMixBatchOperation.
|
||||
std::shared_ptr<CutMixBatchOperation> CutMixBatch(ImageBatchFormat image_batch_format, float alpha, float prob) {
|
||||
auto op = std::make_shared<CutMixBatchOperation>(image_batch_format, alpha, prob);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// CutMixBatch Transform Operation.
|
||||
CutMixBatch::CutMixBatch(ImageBatchFormat image_batch_format, float alpha, float prob)
|
||||
: image_batch_format_(image_batch_format), alpha_(alpha), prob_(prob) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> CutMixBatch::Parse() {
|
||||
return std::make_shared<CutMixBatchOperation>(image_batch_format_, alpha_, prob_);
|
||||
}
|
||||
|
||||
// Function to create CutOutOp.
|
||||
std::shared_ptr<CutOutOperation> CutOut(int32_t length, int32_t num_patches) {
|
||||
auto op = std::make_shared<CutOutOperation>(length, num_patches);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
// CutOutOp.
|
||||
CutOut::CutOut(int32_t length, int32_t num_patches) : length_(length), num_patches_(num_patches) {}
|
||||
|
||||
// Function to create DecodeOperation.
|
||||
std::shared_ptr<DecodeOperation> Decode(bool rgb) {
|
||||
auto op = std::make_shared<DecodeOperation>(rgb);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
std::shared_ptr<TensorOperation> CutOut::Parse() { return std::make_shared<CutOutOperation>(length_, num_patches_); }
|
||||
|
||||
// Decode Transform Operation.
|
||||
Decode::Decode(bool rgb) {}
|
||||
std::shared_ptr<TensorOperation> Decode::Parse() { return std::make_shared<DecodeOperation>(rgb_); }
|
||||
|
||||
#endif
|
||||
#ifdef ENABLE_ACL
|
||||
// Function to create DvppResizeOperation.
|
||||
std::shared_ptr<DvppCropJpegOperation> DvppCropJpeg(std::vector<uint32_t> crop) {
|
||||
|
@ -193,299 +140,355 @@ std::shared_ptr<DvppResizeJpegOperation> DvppResizeJpeg(std::vector<uint32_t> re
|
|||
}
|
||||
#endif
|
||||
|
||||
// Function to create EqualizeOperation.
|
||||
std::shared_ptr<EqualizeOperation> Equalize() {
|
||||
auto op = std::make_shared<EqualizeOperation>();
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
/*
|
||||
// DvppResize Transform Operation.
|
||||
DvppCropJpeg::DvppCropJpeg(std::vector<uint32_t> crop) : crop_(crop) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> DvppCropJpeg::Parse() { return std::make_shared<DvppCropJpegOperation>(crop); }
|
||||
|
||||
// DvppDecodeResize Transform Operation.
|
||||
DvppDecodeResize::DvppDecodeResizeJpeg(std::vector<uint32_t> resize) : resize_(resize) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> DvppDecodeResizeJpeg::Parse() {
|
||||
return std::make_shared<DvppDecodeResizeOperation>(resize);
|
||||
}
|
||||
|
||||
// Function to create HwcToChwOperation.
|
||||
std::shared_ptr<HwcToChwOperation> HWC2CHW() {
|
||||
auto op = std::make_shared<HwcToChwOperation>();
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// DvppDecodeResizeCrop Transform Operation.
|
||||
DvppDecodeResizeCrop::DvppDecodeResizeCropJpeg(std::vector<uint32_t> crop, std::vector<uint32_t> resize)
|
||||
: crop_(crop), resize_(resize) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> DvppDecodeResizeCropJpeg::Parse() {
|
||||
return std::make_shared<DvppDecodeResizeCropOperation>(crop, resize);
|
||||
}
|
||||
|
||||
// Function to create InvertOperation.
|
||||
std::shared_ptr<InvertOperation> Invert() {
|
||||
auto op = std::make_shared<InvertOperation>();
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// DvppCropOperation
|
||||
DvppCropJpeg::DvppCropJpeg(const std::vector<uint32_t> &crop) : crop_(crop) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> DvppCropJpeg::Parse() { return std::make_shared<DvppCropJpegOperation>(); }
|
||||
|
||||
// DvppDecodeResizeOperation
|
||||
DvppDecodeResize::DvppDecodeResize(const std::vector<uint32_t> &resize) : resize_(resize) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> DvppDecodeResize::Parse() { return std::make_shared<DvppDecodeResizeOperation>(); }
|
||||
|
||||
// DvppDecodeJpeg Transform Operation.
|
||||
DvppDecodeJpeg::DvppDecodeJpeg() {}
|
||||
|
||||
std::shared_ptr<TensorOperation> DvppDecodeJpeg::Parse() { return std::make_shared<DvppDecodeJpegOperation>(); }
|
||||
|
||||
// DvppDecodePng Transform Operation.
|
||||
DvppDecodePng::DvppDecodePng() {}
|
||||
|
||||
std::shared_ptr<TensorOperation> DvppDecodePng::Parse() { return std::make_shared<DvppDecodePngOperation>(); }
|
||||
|
||||
// DvppResizeOperation
|
||||
DvppDecodeResize::DvppResizeJpeg(const std::vector<uint32_t> &resize) : resize_(resize) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> DvppDecodeResize::Parse() { return std::make_shared<DvppDecodeResizeOperation>(); }
|
||||
|
||||
// DvppDecodeResizeCropOperation
|
||||
DvppDecodeResizeCrop::DvppDecodeResizeCrop(const std::vector<uint32_t> &crop, const std::vector<uint32_t> &resize)
|
||||
: crop_(crop), resize_(resize) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> DvppDecodeResizeCrop::Parse() {
|
||||
return std::make_shared<DvppDecodeResizeCropOperation>();
|
||||
}
|
||||
|
||||
// Function to create MixUpBatchOperation.
|
||||
std::shared_ptr<MixUpBatchOperation> MixUpBatch(float alpha) {
|
||||
auto op = std::make_shared<MixUpBatchOperation>(alpha);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
// DvppResize Transform Operation.
|
||||
DvppResizeJpeg::DvppResizeJpeg(std::vector<uint32_t> resize) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> DvppResizeJpeg::Parse() { return std::make_shared<DvppResizeJpegOperation>(resize); }
|
||||
#endif
|
||||
|
||||
// Function to create NormalizeOperation.
|
||||
std::shared_ptr<NormalizeOperation> Normalize(std::vector<float> mean, std::vector<float> std) {
|
||||
auto op = std::make_shared<NormalizeOperation>(mean, std);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
*/
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
// Function to create NormalizePadOperation.
|
||||
std::shared_ptr<NormalizePadOperation> NormalizePad(const std::vector<float> &mean, const std::vector<float> &std,
|
||||
const std::string &dtype) {
|
||||
auto op = std::make_shared<NormalizePadOperation>(mean, std, dtype);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// Equalize Transform Operation.
|
||||
Equalize::Equalize() {}
|
||||
|
||||
std::shared_ptr<TensorOperation> Equalize::Parse() { return std::make_shared<EqualizeOperation>(); }
|
||||
// HwcToChw Transform Operation.
|
||||
HWC2CHW::HWC2CHW() {}
|
||||
|
||||
std::shared_ptr<TensorOperation> HWC2CHW::Parse() { return std::make_shared<HwcToChwOperation>(); }
|
||||
|
||||
// Invert Transform Operation.
|
||||
Invert::Invert() {}
|
||||
|
||||
std::shared_ptr<TensorOperation> Invert::Parse() { return std::make_shared<InvertOperation>(); }
|
||||
|
||||
// MixUpBatch Transform Operation.
|
||||
MixUpBatch::MixUpBatch(float alpha) : alpha_(alpha) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> MixUpBatch::Parse() { return std::make_shared<MixUpBatchOperation>(alpha_); }
|
||||
#endif
|
||||
|
||||
// Normalize Transform Operation.
|
||||
Normalize::Normalize(std::vector<float> mean, std::vector<float> std) : mean_(mean), std_(std) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> Normalize::Parse() { return std::make_shared<NormalizeOperation>(mean_, std_); }
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
// NormalizePad Transform Operation.
|
||||
NormalizePad::NormalizePad(const std::vector<float> &mean, const std::vector<float> &std, const std::string &dtype)
|
||||
: mean_(mean), std_(std), dtype_(dtype) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> NormalizePad::Parse() {
|
||||
return std::make_shared<NormalizePadOperation>(mean_, std_, dtype_);
|
||||
}
|
||||
|
||||
// Function to create PadOperation.
|
||||
std::shared_ptr<PadOperation> Pad(std::vector<int32_t> padding, std::vector<uint8_t> fill_value,
|
||||
BorderType padding_mode) {
|
||||
auto op = std::make_shared<PadOperation>(padding, fill_value, padding_mode);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// Pad Transform Operation.
|
||||
Pad::Pad(std::vector<int32_t> padding, std::vector<uint8_t> fill_value, BorderType padding_mode)
|
||||
: padding_(padding), fill_value_(fill_value), padding_mode_(padding_mode) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> Pad::Parse() {
|
||||
return std::make_shared<PadOperation>(padding_, fill_value_, padding_mode_);
|
||||
}
|
||||
|
||||
// Function to create RandomAffineOperation.
|
||||
std::shared_ptr<RandomAffineOperation> RandomAffine(const std::vector<float_t> °rees,
|
||||
const std::vector<float_t> &translate_range,
|
||||
const std::vector<float_t> &scale_range,
|
||||
const std::vector<float_t> &shear_ranges,
|
||||
InterpolationMode interpolation,
|
||||
const std::vector<uint8_t> &fill_value) {
|
||||
auto op = std::make_shared<RandomAffineOperation>(degrees, translate_range, scale_range, shear_ranges, interpolation,
|
||||
fill_value);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomAffine Transform Operation.
|
||||
RandomAffine::RandomAffine(const std::vector<float_t> °rees, const std::vector<float_t> &translate_range,
|
||||
const std::vector<float_t> &scale_range, const std::vector<float_t> &shear_ranges,
|
||||
InterpolationMode interpolation, const std::vector<uint8_t> &fill_value)
|
||||
: degrees_(degrees),
|
||||
translate_range_(translate_range),
|
||||
scale_range_(scale_range),
|
||||
shear_ranges_(shear_ranges),
|
||||
interpolation_(interpolation),
|
||||
fill_value_(fill_value) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomAffine::Parse() {
|
||||
return std::make_shared<RandomAffineOperation>(degrees_, translate_range_, scale_range_, shear_ranges_,
|
||||
interpolation_, fill_value_);
|
||||
}
|
||||
|
||||
// Function to create RandomColorOperation.
|
||||
std::shared_ptr<RandomColorOperation> RandomColor(float t_lb, float t_ub) {
|
||||
auto op = std::make_shared<RandomColorOperation>(t_lb, t_ub);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomColor Transform Operation.
|
||||
RandomColor::RandomColor(float t_lb, float t_ub) : t_lb_(t_lb), t_ub_(t_ub) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomColor::Parse() { return std::make_shared<RandomColorOperation>(t_lb_, t_ub_); }
|
||||
|
||||
// RandomColorAdjust Transform Operation.
|
||||
RandomColorAdjust::RandomColorAdjust(std::vector<float> brightness, std::vector<float> contrast,
|
||||
std::vector<float> saturation, std::vector<float> hue)
|
||||
: brightness_(brightness), contrast_(contrast), saturation_(saturation), hue_(hue) {}
|
||||
std::shared_ptr<TensorOperation> RandomColorAdjust::Parse() {
|
||||
return std::make_shared<RandomColorAdjustOperation>(brightness_, contrast_, saturation_, hue_);
|
||||
}
|
||||
|
||||
std::shared_ptr<TensorOp> RandomColorOperation::Build() {
|
||||
std::shared_ptr<RandomColorOp> tensor_op = std::make_shared<RandomColorOp>(t_lb_, t_ub_);
|
||||
return tensor_op;
|
||||
// RandomCrop Transform Operation.
|
||||
RandomCrop::RandomCrop(std::vector<int32_t> size, std::vector<int32_t> padding, bool pad_if_needed,
|
||||
std::vector<uint8_t> fill_value, BorderType padding_mode)
|
||||
: size_(size),
|
||||
padding_(padding),
|
||||
pad_if_needed_(pad_if_needed),
|
||||
fill_value_(fill_value),
|
||||
padding_mode_(padding_mode) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomCrop::Parse() {
|
||||
return std::make_shared<RandomCropOperation>(size_, padding_, pad_if_needed_, fill_value_, padding_mode_);
|
||||
}
|
||||
|
||||
// Function to create RandomColorAdjustOperation.
|
||||
std::shared_ptr<RandomColorAdjustOperation> RandomColorAdjust(std::vector<float> brightness,
|
||||
std::vector<float> contrast,
|
||||
std::vector<float> saturation, std::vector<float> hue) {
|
||||
auto op = std::make_shared<RandomColorAdjustOperation>(brightness, contrast, saturation, hue);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomCropDecodeResize Transform Operation.
|
||||
RandomCropDecodeResize::RandomCropDecodeResize(std::vector<int32_t> size, std::vector<float> scale,
|
||||
std::vector<float> ratio, InterpolationMode interpolation,
|
||||
int32_t max_attempts)
|
||||
: size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomCropDecodeResize::Parse() {
|
||||
return std::make_shared<RandomCropDecodeResizeOperation>(size_, scale_, ratio_, interpolation_, max_attempts_);
|
||||
}
|
||||
|
||||
// Function to create RandomCropOperation.
|
||||
std::shared_ptr<RandomCropOperation> RandomCrop(std::vector<int32_t> size, std::vector<int32_t> padding,
|
||||
bool pad_if_needed, std::vector<uint8_t> fill_value,
|
||||
BorderType padding_mode) {
|
||||
auto op = std::make_shared<RandomCropOperation>(size, padding, pad_if_needed, fill_value, padding_mode);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomCropWithBBox Transform Operation.
|
||||
RandomCropWithBBox::RandomCropWithBBox(std::vector<int32_t> size, std::vector<int32_t> padding, bool pad_if_needed,
|
||||
std::vector<uint8_t> fill_value, BorderType padding_mode)
|
||||
: size_(size),
|
||||
padding_(padding),
|
||||
pad_if_needed_(pad_if_needed),
|
||||
fill_value_(fill_value),
|
||||
padding_mode_(padding_mode) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomCropWithBBox::Parse() {
|
||||
return std::make_shared<RandomCropWithBBoxOperation>(size_, padding_, pad_if_needed_, fill_value_, padding_mode_);
|
||||
}
|
||||
|
||||
// Function to create RandomCropDecodeResizeOperation.
|
||||
std::shared_ptr<RandomCropDecodeResizeOperation> RandomCropDecodeResize(std::vector<int32_t> size,
|
||||
std::vector<float> scale,
|
||||
std::vector<float> ratio,
|
||||
InterpolationMode interpolation,
|
||||
int32_t max_attempts) {
|
||||
auto op = std::make_shared<RandomCropDecodeResizeOperation>(size, scale, ratio, interpolation, max_attempts);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomHorizontalFlip.
|
||||
RandomHorizontalFlip::RandomHorizontalFlip(float prob) : probability_(prob) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomHorizontalFlip::Parse() {
|
||||
return std::make_shared<RandomHorizontalFlipOperation>(probability_);
|
||||
}
|
||||
|
||||
// Function to create RandomCropWithBBoxOperation.
|
||||
std::shared_ptr<RandomCropWithBBoxOperation> RandomCropWithBBox(std::vector<int32_t> size, std::vector<int32_t> padding,
|
||||
bool pad_if_needed, std::vector<uint8_t> fill_value,
|
||||
BorderType padding_mode) {
|
||||
auto op = std::make_shared<RandomCropWithBBoxOperation>(size, padding, pad_if_needed, fill_value, padding_mode);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomHorizontalFlipWithBBox
|
||||
RandomHorizontalFlipWithBBox::RandomHorizontalFlipWithBBox(float prob) : probability_(prob) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomHorizontalFlipWithBBox::Parse() {
|
||||
return std::make_shared<RandomHorizontalFlipWithBBoxOperation>(probability_);
|
||||
}
|
||||
|
||||
// Function to create RandomHorizontalFlipOperation.
|
||||
std::shared_ptr<RandomHorizontalFlipOperation> RandomHorizontalFlip(float prob) {
|
||||
auto op = std::make_shared<RandomHorizontalFlipOperation>(prob);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomPosterize Transform Operation.
|
||||
RandomPosterize::RandomPosterize(const std::vector<uint8_t> &bit_range) : bit_range_(bit_range) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomPosterize::Parse() {
|
||||
return std::make_shared<RandomPosterizeOperation>(bit_range_);
|
||||
}
|
||||
|
||||
// Function to create RandomHorizontalFlipOperation.
|
||||
std::shared_ptr<RandomHorizontalFlipWithBBoxOperation> RandomHorizontalFlipWithBBox(float prob) {
|
||||
auto op = std::make_shared<RandomHorizontalFlipWithBBoxOperation>(prob);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomResize Transform Operation.
|
||||
RandomResize::RandomResize(std::vector<int32_t> size) : size_(size) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomResize::Parse() { return std::make_shared<RandomResizeOperation>(size_); }
|
||||
|
||||
// RandomResizeWithBBox Transform Operation.
|
||||
RandomResizeWithBBox::RandomResizeWithBBox(std::vector<int32_t> size) : size_(size) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomResizeWithBBox::Parse() {
|
||||
return std::make_shared<RandomResizeWithBBoxOperation>(size_);
|
||||
}
|
||||
|
||||
// Function to create RandomPosterizeOperation.
|
||||
std::shared_ptr<RandomPosterizeOperation> RandomPosterize(const std::vector<uint8_t> &bit_range) {
|
||||
auto op = std::make_shared<RandomPosterizeOperation>(bit_range);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomResizedCrop Transform Operation.
|
||||
RandomResizedCrop::RandomResizedCrop(std::vector<int32_t> size, std::vector<float> scale, std::vector<float> ratio,
|
||||
InterpolationMode interpolation, int32_t max_attempts)
|
||||
: size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomResizedCrop::Parse() {
|
||||
return std::make_shared<RandomResizedCropOperation>(size_, scale_, ratio_, interpolation_, max_attempts_);
|
||||
}
|
||||
|
||||
// Function to create RandomResizeOperation.
|
||||
std::shared_ptr<RandomResizeOperation> RandomResize(std::vector<int32_t> size) {
|
||||
auto op = std::make_shared<RandomResizeOperation>(size);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomResizedCrop Transform Operation.
|
||||
RandomResizedCropWithBBox::RandomResizedCropWithBBox(std::vector<int32_t> size, std::vector<float> scale,
|
||||
std::vector<float> ratio, InterpolationMode interpolation,
|
||||
int32_t max_attempts)
|
||||
: size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomResizedCropWithBBox::Parse() {
|
||||
return std::make_shared<RandomResizedCropWithBBoxOperation>(size_, scale_, ratio_, interpolation_, max_attempts_);
|
||||
}
|
||||
|
||||
// Function to create RandomResizeWithBBoxOperation.
|
||||
std::shared_ptr<RandomResizeWithBBoxOperation> RandomResizeWithBBox(std::vector<int32_t> size) {
|
||||
auto op = std::make_shared<RandomResizeWithBBoxOperation>(size);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomRotation Transform Operation.
|
||||
RandomRotation::RandomRotation(std::vector<float> degrees, InterpolationMode interpolation_mode, bool expand,
|
||||
std::vector<float> center, std::vector<uint8_t> fill_value)
|
||||
: degrees_(degrees),
|
||||
interpolation_mode_(interpolation_mode),
|
||||
expand_(expand),
|
||||
center_(center),
|
||||
fill_value_(fill_value) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomRotation::Parse() {
|
||||
return std::make_shared<RandomRotationOperation>(degrees_, interpolation_mode_, expand_, center_, fill_value_);
|
||||
}
|
||||
|
||||
// Function to create RandomResizedCropOperation.
|
||||
std::shared_ptr<RandomResizedCropOperation> RandomResizedCrop(std::vector<int32_t> size, std::vector<float> scale,
|
||||
std::vector<float> ratio, InterpolationMode interpolation,
|
||||
int32_t max_attempts) {
|
||||
auto op = std::make_shared<RandomResizedCropOperation>(size, scale, ratio, interpolation, max_attempts);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomSelectSubpolicy Transform Operation.
|
||||
// FIXME - Provide TensorTransform support for policy
|
||||
RandomSelectSubpolicy::RandomSelectSubpolicy(
|
||||
std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy)
|
||||
: policy_(policy) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomSelectSubpolicy::Parse() {
|
||||
return std::make_shared<RandomSelectSubpolicyOperation>(policy_);
|
||||
}
|
||||
|
||||
// Function to create RandomResizedCropOperation.
|
||||
std::shared_ptr<RandomResizedCropWithBBoxOperation> RandomResizedCropWithBBox(std::vector<int32_t> size,
|
||||
std::vector<float> scale,
|
||||
std::vector<float> ratio,
|
||||
InterpolationMode interpolation,
|
||||
int32_t max_attempts) {
|
||||
auto op = std::make_shared<RandomResizedCropWithBBoxOperation>(size, scale, ratio, interpolation, max_attempts);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomSharpness Transform Operation.
|
||||
RandomSharpness::RandomSharpness(std::vector<float> degrees) : degrees_(degrees) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomSharpness::Parse() {
|
||||
return std::make_shared<RandomSharpnessOperation>(degrees_);
|
||||
}
|
||||
|
||||
// Function to create RandomRotationOperation.
|
||||
std::shared_ptr<RandomRotationOperation> RandomRotation(std::vector<float> degrees, InterpolationMode resample,
|
||||
bool expand, std::vector<float> center,
|
||||
std::vector<uint8_t> fill_value) {
|
||||
auto op = std::make_shared<RandomRotationOperation>(degrees, resample, expand, center, fill_value);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomSolarize Transform Operation.
|
||||
RandomSolarize::RandomSolarize(std::vector<uint8_t> threshold) : threshold_(threshold) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomSolarize::Parse() {
|
||||
return std::make_shared<RandomSolarizeOperation>(threshold_);
|
||||
}
|
||||
|
||||
// Function to create RandomSharpnessOperation.
|
||||
std::shared_ptr<RandomSharpnessOperation> RandomSharpness(std::vector<float> degrees) {
|
||||
auto op = std::make_shared<RandomSharpnessOperation>(degrees);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomVerticalFlip Transform Operation.
|
||||
RandomVerticalFlip::RandomVerticalFlip(float prob) : probability_(prob) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomVerticalFlip::Parse() {
|
||||
return std::make_shared<RandomVerticalFlipOperation>(probability_);
|
||||
}
|
||||
|
||||
// Function to create RandomSolarizeOperation.
|
||||
std::shared_ptr<RandomSolarizeOperation> RandomSolarize(std::vector<uint8_t> threshold) {
|
||||
auto op = std::make_shared<RandomSolarizeOperation>(threshold);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RandomVerticalFlipWithBBox Transform Operation.
|
||||
RandomVerticalFlipWithBBox::RandomVerticalFlipWithBBox(float prob) : probability_(prob) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RandomVerticalFlipWithBBox::Parse() {
|
||||
return std::make_shared<RandomVerticalFlipWithBBoxOperation>(probability_);
|
||||
}
|
||||
|
||||
// Function to create RandomSelectSubpolicyOperation.
|
||||
std::shared_ptr<RandomSelectSubpolicyOperation> RandomSelectSubpolicy(
|
||||
std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy) {
|
||||
auto op = std::make_shared<RandomSelectSubpolicyOperation>(policy);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
// Rescale Transform Operation.
|
||||
Rescale::Rescale(float rescale, float shift) : rescale_(rescale), shift_(shift) {}
|
||||
|
||||
// Function to create RandomVerticalFlipOperation.
|
||||
std::shared_ptr<RandomVerticalFlipOperation> RandomVerticalFlip(float prob) {
|
||||
auto op = std::make_shared<RandomVerticalFlipOperation>(prob);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
|
||||
// Function to create RandomVerticalFlipWithBBoxOperation.
|
||||
std::shared_ptr<RandomVerticalFlipWithBBoxOperation> RandomVerticalFlipWithBBox(float prob) {
|
||||
auto op = std::make_shared<RandomVerticalFlipWithBBoxOperation>(prob);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
|
||||
// Function to create RescaleOperation.
|
||||
std::shared_ptr<RescaleOperation> Rescale(float rescale, float shift) {
|
||||
auto op = std::make_shared<RescaleOperation>(rescale, shift);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
std::shared_ptr<TensorOperation> Rescale::Parse() { return std::make_shared<RescaleOperation>(rescale_, shift_); }
|
||||
|
||||
#endif
|
||||
// Function to create ResizeOperation.
|
||||
std::shared_ptr<ResizeOperation> Resize(std::vector<int32_t> size, InterpolationMode interpolation) {
|
||||
auto op = std::make_shared<ResizeOperation>(size, interpolation);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
// Resize Transform Operation.
|
||||
Resize::Resize(std::vector<int32_t> size, InterpolationMode interpolation)
|
||||
: size_(size), interpolation_(interpolation) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> Resize::Parse() { return std::make_shared<ResizeOperation>(size_, interpolation_); }
|
||||
|
||||
#ifdef ENABLE_ANDROID
|
||||
// Function to create RotateOperation.
|
||||
std::shared_ptr<RotateOperation> Rotate() {
|
||||
auto op = std::make_shared<RotateOperation>();
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
// Rotate Transform Operation.
|
||||
Rotate::Rotate() {}
|
||||
|
||||
std::shared_ptr<TensorOperation> Rotate::Parse() { return std::make_shared<RotateOperation>(); }
|
||||
#endif
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
// Function to create ResizeWithBBoxOperation.
|
||||
std::shared_ptr<ResizeWithBBoxOperation> ResizeWithBBox(std::vector<int32_t> size, InterpolationMode interpolation) {
|
||||
auto op = std::make_shared<ResizeWithBBoxOperation>(size, interpolation);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// ResizeWithBBox Transform Operation.
|
||||
ResizeWithBBox::ResizeWithBBox(std::vector<int32_t> size, InterpolationMode interpolation)
|
||||
: size_(size), interpolation_(interpolation) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> ResizeWithBBox::Parse() {
|
||||
return std::make_shared<ResizeWithBBoxOperation>(size_, interpolation_);
|
||||
}
|
||||
|
||||
// Function to create RgbaToBgrOperation.
|
||||
std::shared_ptr<RgbaToBgrOperation> RGBA2BGR() {
|
||||
auto op = std::make_shared<RgbaToBgrOperation>();
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// RgbaToBgr Transform Operation.
|
||||
RGBA2BGR::RGBA2BGR() {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RGBA2BGR::Parse() { return std::make_shared<RgbaToBgrOperation>(); }
|
||||
|
||||
// RgbaToRgb Transform Operation.
|
||||
RGBA2RGB::RGBA2RGB() {}
|
||||
|
||||
std::shared_ptr<TensorOperation> RGBA2RGB::Parse() { return std::make_shared<RgbaToRgbOperation>(); }
|
||||
|
||||
// SoftDvppDecodeRandomCropResizeJpeg Transform Operation.
|
||||
SoftDvppDecodeRandomCropResizeJpeg::SoftDvppDecodeRandomCropResizeJpeg(std::vector<int32_t> size,
|
||||
std::vector<float> scale,
|
||||
std::vector<float> ratio, int32_t max_attempts)
|
||||
: size_(size), scale_(scale), ratio_(ratio), max_attempts_(max_attempts) {}
|
||||
std::shared_ptr<TensorOperation> SoftDvppDecodeRandomCropResizeJpeg::Parse() {
|
||||
return std::make_shared<SoftDvppDecodeRandomCropResizeJpegOperation>(size_, scale_, ratio_, max_attempts_);
|
||||
}
|
||||
|
||||
// Function to create RgbaToRgbOperation.
|
||||
std::shared_ptr<RgbaToRgbOperation> RGBA2RGB() {
|
||||
auto op = std::make_shared<RgbaToRgbOperation>();
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// SoftDvppDecodeResizeJpeg Transform Operation.
|
||||
SoftDvppDecodeResizeJpeg::SoftDvppDecodeResizeJpeg(std::vector<int32_t> size) : size_(size) {}
|
||||
|
||||
std::shared_ptr<TensorOperation> SoftDvppDecodeResizeJpeg::Parse() {
|
||||
return std::make_shared<SoftDvppDecodeResizeJpegOperation>(size_);
|
||||
}
|
||||
|
||||
// Function to create SoftDvppDecodeRandomCropResizeJpegOperation.
|
||||
std::shared_ptr<SoftDvppDecodeRandomCropResizeJpegOperation> SoftDvppDecodeRandomCropResizeJpeg(
|
||||
std::vector<int32_t> size, std::vector<float> scale, std::vector<float> ratio, int32_t max_attempts) {
|
||||
auto op = std::make_shared<SoftDvppDecodeRandomCropResizeJpegOperation>(size, scale, ratio, max_attempts);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
// SwapRedBlue Transform Operation.
|
||||
SwapRedBlue::SwapRedBlue() {}
|
||||
|
||||
std::shared_ptr<TensorOperation> SwapRedBlue::Parse() { return std::make_shared<SwapRedBlueOperation>(); }
|
||||
|
||||
// UniformAug Transform Operation.
|
||||
UniformAugment::UniformAugment(std::vector<std::shared_ptr<TensorTransform>> transforms, int32_t num_ops) {
|
||||
// Convert ops from TensorTransform to TensorOperation
|
||||
(void)std::transform(
|
||||
transforms.begin(), transforms.end(), std::back_inserter(transforms_),
|
||||
[](std::shared_ptr<TensorTransform> operation) -> std::shared_ptr<TensorOperation> { return operation->Parse(); });
|
||||
num_ops_ = num_ops;
|
||||
}
|
||||
|
||||
// Function to create SoftDvppDecodeResizeJpegOperation.
|
||||
std::shared_ptr<SoftDvppDecodeResizeJpegOperation> SoftDvppDecodeResizeJpeg(std::vector<int32_t> size) {
|
||||
auto op = std::make_shared<SoftDvppDecodeResizeJpegOperation>(size);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
|
||||
// Function to create SwapRedBlueOperation.
|
||||
std::shared_ptr<SwapRedBlueOperation> SwapRedBlue() {
|
||||
auto op = std::make_shared<SwapRedBlueOperation>();
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
}
|
||||
|
||||
// Function to create UniformAugOperation.
|
||||
std::shared_ptr<UniformAugOperation> UniformAugment(std::vector<std::shared_ptr<TensorOperation>> transforms,
|
||||
int32_t num_ops) {
|
||||
auto op = std::make_shared<UniformAugOperation>(transforms, num_ops);
|
||||
// Input validation
|
||||
return op->ValidateParams() ? op : nullptr;
|
||||
std::shared_ptr<TensorOperation> UniformAugment::Parse() {
|
||||
return std::make_shared<UniformAugOperation>(transforms_, num_ops_);
|
||||
}
|
||||
#endif
|
||||
|
||||
// FIXME - Move these DVPP Derived TensorOperation classes to IR level
|
||||
/* ####################################### Derived TensorOperation classes ################################# */
|
||||
|
||||
#ifdef ENABLE_ACL
|
||||
// DvppCropOperation
|
||||
DvppCropJpegOperation::DvppCropJpegOperation(const std::vector<uint32_t> &crop) : crop_(crop) {}
|
||||
|
|
|
@ -33,9 +33,16 @@ namespace dataset {
|
|||
class Execute {
|
||||
public:
|
||||
/// \brief Constructor
|
||||
// FIXME - Temporarily overload Execute to support both TensorOperation and TensorTransform
|
||||
explicit Execute(std::shared_ptr<TensorOperation> op, std::string deviceType = "CPU");
|
||||
explicit Execute(std::shared_ptr<TensorTransform> op, std::string deviceType = "CPU");
|
||||
// explicit Execute(TensorTransform op, std::string deviceType = "CPU");
|
||||
explicit Execute(TensorTransform *op, std::string deviceType = "CPU");
|
||||
|
||||
explicit Execute(std::vector<std::shared_ptr<TensorOperation>> ops, std::string deviceType = "CPU");
|
||||
explicit Execute(std::vector<std::shared_ptr<TensorTransform>> ops, std::string deviceType = "CPU");
|
||||
explicit Execute(const std::vector<std::reference_wrapper<TensorTransform>> ops, std::string deviceType = "CPU");
|
||||
explicit Execute(std::vector<TensorTransform *> ops, std::string deviceType = "CPU");
|
||||
|
||||
/// \brief Destructor
|
||||
~Execute();
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
namespace mindspore {
|
||||
namespace dataset {
|
||||
// Abstract class to represent a tensor transform operation in the data pipeline.
|
||||
/// \class TensorTransform transforms.h
|
||||
/// \brief A base class to represent a tensor transform operation in the data pipeline.
|
||||
class TensorTransform : public std::enable_shared_from_this<TensorTransform> {
|
||||
public:
|
||||
/// \brief Constructor
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -26,69 +26,141 @@
|
|||
#include "minddata/dataset/include/constants.h"
|
||||
#include "minddata/dataset/include/transforms.h"
|
||||
|
||||
// FIXME - This internal IR header will be removed when external API classes are provided
|
||||
#include "minddata/dataset/kernels/ir/vision/vision_ir.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace dataset {
|
||||
|
||||
// Transform operations for performing computer vision.
|
||||
namespace vision {
|
||||
|
||||
// Transform Op classes (in alphabetical order)
|
||||
class CenterCropOperation;
|
||||
class CropOperation;
|
||||
class DecodeOperation;
|
||||
class NormalizeOperation;
|
||||
class ResizeOperation;
|
||||
// Forward Declarations
|
||||
class RotateOperation;
|
||||
|
||||
/// \brief Function to create a CenterCrop TensorOperation.
|
||||
/// \brief CenterCrop TensorTransform.
|
||||
/// \notes Crops the input image at the center to the given size.
|
||||
/// \param[in] size A vector representing the output size of the cropped image.
|
||||
/// If size is a single value, a square crop of size (size, size) is returned.
|
||||
/// If size has 2 values, it should be (height, width).
|
||||
/// \return Shared pointer to the current TensorOperation.
|
||||
std::shared_ptr<CenterCropOperation> CenterCrop(std::vector<int32_t> size);
|
||||
class CenterCrop : public TensorTransform {
|
||||
public:
|
||||
/// \brief Constructor.
|
||||
/// \param[in] size A vector representing the output size of the cropped image.
|
||||
/// If size is a single value, a square crop of size (size, size) is returned.
|
||||
/// If size has 2 values, it should be (height, width).
|
||||
explicit CenterCrop(std::vector<int32_t> size);
|
||||
|
||||
/// \brief Function to create a Crop TensorOp
|
||||
/// \brief Destructor.
|
||||
~CenterCrop() = default;
|
||||
|
||||
/// \brief Function to convert TensorTransform object into a TensorOperation object.
|
||||
/// \return Shared pointer to TensorOperation object.
|
||||
std::shared_ptr<TensorOperation> Parse() override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> size_;
|
||||
};
|
||||
|
||||
/// \brief Crop TensorTransform.
|
||||
/// \notes Crop an image based on location and crop size
|
||||
/// \param[in] coordinates Starting location of crop. Must be a vector of two values, in the form of {x_coor, y_coor}
|
||||
/// \param[in] size Size of the cropped area.
|
||||
/// If size is a single value, a square crop of size (size, size) is returned.
|
||||
/// If size has 2 values, it should be (height, width).
|
||||
/// \return Shared pointer to the current TensorOp
|
||||
std::shared_ptr<CropOperation> Crop(std::vector<int32_t> coordinates, std::vector<int32_t> size);
|
||||
class Crop : public TensorTransform {
|
||||
public:
|
||||
/// \brief Constructor.
|
||||
/// \param[in] coordinates Starting location of crop. Must be a vector of two values, in the form of {x_coor, y_coor}
|
||||
/// \param[in] size Size of the cropped area.
|
||||
/// If size is a single value, a square crop of size (size, size) is returned.
|
||||
/// If size has 2 values, it should be (height, width).
|
||||
Crop(std::vector<int32_t> coordinates, std::vector<int32_t> size);
|
||||
|
||||
/// \brief Function to create a Decode TensorOperation.
|
||||
/// \brief Destructor.
|
||||
~Crop() = default;
|
||||
|
||||
/// \brief Function to convert TensorTransform object into a TensorOperation object.
|
||||
/// \return Shared pointer to TensorOperation object.
|
||||
std::shared_ptr<TensorOperation> Parse() override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> coordinates_;
|
||||
std::vector<int32_t> size_;
|
||||
};
|
||||
|
||||
/// \brief Decode TensorTransform.
|
||||
/// \notes Decode the input image in RGB mode.
|
||||
/// \param[in] rgb A boolean of whether to decode in RGB mode or not.
|
||||
/// \return Shared pointer to the current TensorOperation.
|
||||
std::shared_ptr<DecodeOperation> Decode(bool rgb = true);
|
||||
class Decode : public TensorTransform {
|
||||
public:
|
||||
/// \brief Constructor.
|
||||
/// \param[in] rgb A boolean of whether to decode in RGB mode or not.
|
||||
explicit Decode(bool rgb = true);
|
||||
|
||||
/// \brief Function to create a Normalize TensorOperation.
|
||||
/// \brief Destructor.
|
||||
~Decode() = default;
|
||||
|
||||
/// \brief Function to convert TensorTransform object into a TensorOperation object.
|
||||
/// \return Shared pointer to TensorOperation object.
|
||||
std::shared_ptr<TensorOperation> Parse() override;
|
||||
|
||||
private:
|
||||
bool rgb_;
|
||||
};
|
||||
|
||||
/// \brief Normalize TensorTransform.
|
||||
/// \notes Normalize the input image with respect to mean and standard deviation.
|
||||
/// \param[in] mean A vector of mean values for each channel, w.r.t channel order.
|
||||
/// The mean values must be in range [0.0, 255.0].
|
||||
/// \param[in] std A vector of standard deviations for each channel, w.r.t. channel order.
|
||||
/// The standard deviation values must be in range (0.0, 255.0]
|
||||
/// \return Shared pointer to the current TensorOperation.
|
||||
std::shared_ptr<NormalizeOperation> Normalize(std::vector<float> mean, std::vector<float> std);
|
||||
class Normalize : public TensorTransform {
|
||||
public:
|
||||
/// \brief Constructor.
|
||||
/// \param[in] mean A vector of mean values for each channel, w.r.t channel order.
|
||||
/// The mean values must be in range [0.0, 255.0].
|
||||
/// \param[in] std A vector of standard deviations for each channel, w.r.t. channel order.
|
||||
/// The standard deviation values must be in range (0.0, 255.0]
|
||||
Normalize(std::vector<float> mean, std::vector<float> std);
|
||||
|
||||
/// \brief Function to create a Resize TensorOperation.
|
||||
/// \brief Destructor.
|
||||
~Normalize() = default;
|
||||
|
||||
/// \brief Function to convert TensorTransform object into a TensorOperation object.
|
||||
/// \return Shared pointer to TensorOperation object.
|
||||
std::shared_ptr<TensorOperation> Parse() override;
|
||||
|
||||
private:
|
||||
std::vector<float> mean_;
|
||||
std::vector<float> std_;
|
||||
};
|
||||
|
||||
/// \brief Resize TensorTransform.
|
||||
/// \notes Resize the input image to the given size.
|
||||
/// \param[in] size A vector representing the output size of the resized image.
|
||||
/// If size is a single value, the image will be resized to this value with
|
||||
/// the same image aspect ratio. If size has 2 values, it should be (height, width).
|
||||
/// \param[in] interpolation An enum for the mode of interpolation
|
||||
/// \return Shared pointer to the current TensorOperation.
|
||||
std::shared_ptr<ResizeOperation> Resize(std::vector<int32_t> size,
|
||||
InterpolationMode interpolation = InterpolationMode::kLinear);
|
||||
class Resize : public TensorTransform {
|
||||
public:
|
||||
/// \brief Constructor.
|
||||
/// \param[in] size A vector representing the output size of the resized image.
|
||||
/// If size is a single value, the image will be resized to this value with
|
||||
/// the same image aspect ratio. If size has 2 values, it should be (height, width).
|
||||
/// \param[in] interpolation An enum for the mode of interpolation
|
||||
explicit Resize(std::vector<int32_t> size, InterpolationMode interpolation = InterpolationMode::kLinear);
|
||||
|
||||
/// \brief Applies an rotate transformation to an image.
|
||||
/// \brief Destructor.
|
||||
~Resize() = default;
|
||||
|
||||
/// \brief Function to convert TensorTransform object into a TensorOperation object.
|
||||
/// \return Shared pointer to TensorOperation object.
|
||||
std::shared_ptr<TensorOperation> Parse() override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> size_;
|
||||
InterpolationMode interpolation_;
|
||||
};
|
||||
|
||||
/// \brief Rotate TensorTransform.
|
||||
/// \notes Rotate the input image using a specified angle id.
|
||||
/// \return Shared pointer to the current TensorOperation.
|
||||
std::shared_ptr<RotateOperation> Rotate();
|
||||
class Rotate : public TensorTransform {
|
||||
public:
|
||||
/// \brief Constructor.
|
||||
Rotate();
|
||||
|
||||
/// \brief Destructor.
|
||||
~Rotate() = default;
|
||||
|
||||
/// \brief Function to convert TensorTransform object into a TensorOperation object.
|
||||
/// \return Shared pointer to TensorOperation object.
|
||||
std::shared_ptr<TensorOperation> Parse() override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<RotateOperation> op_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
|
|
|
@ -542,6 +542,11 @@ Status RandomColorOperation::ValidateParams() {
|
|||
return Status::OK();
|
||||
}
|
||||
|
||||
std::shared_ptr<TensorOp> RandomColorOperation::Build() {
|
||||
std::shared_ptr<RandomColorOp> tensor_op = std::make_shared<RandomColorOp>(t_lb_, t_ub_);
|
||||
return tensor_op;
|
||||
}
|
||||
|
||||
Status RandomColorOperation::to_json(nlohmann::json *out_json) {
|
||||
(*out_json)["degrees"] = std::vector<float>{t_lb_, t_ub_};
|
||||
return Status::OK();
|
||||
|
|
|
@ -79,51 +79,6 @@ constexpr char kSoftDvppDecodeResizeJpegOperation[] = "SoftDvppDecodeResizeJpeg"
|
|||
constexpr char kSwapRedBlueOperation[] = "SwapRedBlue";
|
||||
constexpr char kUniformAugOperation[] = "UniformAug";
|
||||
|
||||
// Transform Op classes (in alphabetical order)
|
||||
class AutoContrastOperation;
|
||||
class BoundingBoxAugmentOperation;
|
||||
class CenterCropOperation;
|
||||
class CropOperation;
|
||||
class CutMixBatchOperation;
|
||||
class CutOutOperation;
|
||||
class DecodeOperation;
|
||||
class EqualizeOperation;
|
||||
class HwcToChwOperation;
|
||||
class InvertOperation;
|
||||
class MixUpBatchOperation;
|
||||
class NormalizeOperation;
|
||||
class NormalizePadOperation;
|
||||
class PadOperation;
|
||||
class RandomAffineOperation;
|
||||
class RandomColorAdjustOperation;
|
||||
class RandomColorOperation;
|
||||
class RandomCropDecodeResizeOperation;
|
||||
class RandomCropOperation;
|
||||
class RandomCropWithBBoxOperation;
|
||||
class RandomHorizontalFlipOperation;
|
||||
class RandomHorizontalFlipWithBBoxOperation;
|
||||
class RandomPosterizeOperation;
|
||||
class RandomResizedCropOperation;
|
||||
class RandomResizedCropWithBBoxOperation;
|
||||
class RandomResizeOperation;
|
||||
class RandomResizeWithBBoxOperation;
|
||||
class RandomRotationOperation;
|
||||
class RandomSelectSubpolicyOperation;
|
||||
class RandomSharpnessOperation;
|
||||
class RandomSolarizeOperation;
|
||||
class RandomVerticalFlipOperation;
|
||||
class RandomVerticalFlipWithBBoxOperation;
|
||||
class RescaleOperation;
|
||||
class ResizeOperation;
|
||||
class ResizeWithBBoxOperation;
|
||||
class RgbaToBgrOperation;
|
||||
class RgbaToRgbOperation;
|
||||
class RotateOperation;
|
||||
class SoftDvppDecodeRandomCropResizeJpegOperation;
|
||||
class SoftDvppDecodeResizeJpegOperation;
|
||||
class SwapRedBlueOperation;
|
||||
class UniformAugOperation;
|
||||
|
||||
/* ####################################### Derived TensorOperation classes ################################# */
|
||||
|
||||
class AutoContrastOperation : public TensorOperation {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "common/common_test.h"
|
||||
#include "include/api/types.h"
|
||||
#include "minddata/dataset/include/execute.h"
|
||||
#include "minddata/dataset/include/transforms.h"
|
||||
#include "minddata/dataset/include/vision.h"
|
||||
#ifdef ENABLE_ACL
|
||||
#include "minddata/dataset/include/vision_ascend.h"
|
||||
|
@ -28,6 +29,7 @@
|
|||
#include "include/api/context.h"
|
||||
|
||||
using namespace mindspore;
|
||||
using namespace mindspore::dataset;
|
||||
using namespace mindspore::dataset::vision;
|
||||
|
||||
class TestDE : public ST::Common {
|
||||
|
@ -42,9 +44,13 @@ TEST_F(TestDE, TestResNetPreprocess) {
|
|||
auto image = mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_tensor));
|
||||
|
||||
// Define transform operations
|
||||
mindspore::dataset::Execute Transform(
|
||||
{Decode(), Resize({224, 224}),
|
||||
Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}), HWC2CHW()});
|
||||
auto decode(new vision::Decode());
|
||||
auto resize(new vision::Resize({224, 224}));
|
||||
auto normalize(
|
||||
new vision::Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}));
|
||||
auto hwc2chw(new vision::HWC2CHW());
|
||||
|
||||
mindspore::dataset::Execute Transform({decode, resize, normalize, hwc2chw});
|
||||
|
||||
// Apply transform on images
|
||||
Status rc = Transform(image, &image);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
* Copyright 2020-2021 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.
|
||||
|
@ -61,7 +61,7 @@ TEST_F(MindDataTestCacheOp, DISABLED_TestCacheCApiNestedCache) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> decode_op = vision::Decode();
|
||||
std::shared_ptr<TensorTransform> decode_op = std::make_shared<vision::Decode>();
|
||||
EXPECT_NE(decode_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
* Copyright 2020-2021 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.
|
||||
|
@ -587,10 +587,10 @@ TEST_F(MindDataTestPipeline, TestFilterSuccess1) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> decode_op = vision::Decode(true);
|
||||
std::shared_ptr<TensorTransform> decode_op = std::make_shared<vision::Decode>(true);
|
||||
EXPECT_NE(decode_op, nullptr);
|
||||
|
||||
std::shared_ptr<TensorOperation> resize_op = vision::Resize({64, 64});
|
||||
std::shared_ptr<TensorTransform> resize_op(new vision::Resize({64, 64}));
|
||||
EXPECT_NE(resize_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -888,7 +888,7 @@ TEST_F(MindDataTestPipeline, TestProjectMap) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> random_vertical_flip_op = vision::RandomVerticalFlip(0.5);
|
||||
std::shared_ptr<TensorTransform> random_vertical_flip_op = std::make_shared<vision::RandomVerticalFlip>(0.5);
|
||||
EXPECT_NE(random_vertical_flip_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -937,7 +937,7 @@ TEST_F(MindDataTestPipeline, TestProjectDuplicateColumnFail) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> random_vertical_flip_op = vision::RandomVerticalFlip(0.5);
|
||||
std::shared_ptr<TensorTransform> random_vertical_flip_op = std::make_shared<vision::RandomVerticalFlip>(0.5);
|
||||
EXPECT_NE(random_vertical_flip_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -966,7 +966,7 @@ TEST_F(MindDataTestPipeline, TestMapDuplicateColumnFail) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> random_vertical_flip_op = vision::RandomVerticalFlip(0.5);
|
||||
std::shared_ptr<TensorTransform> random_vertical_flip_op = std::make_shared<vision::RandomVerticalFlip>(0.5);
|
||||
EXPECT_NE(random_vertical_flip_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -1011,7 +1011,7 @@ TEST_F(MindDataTestPipeline, TestProjectMapAutoInjection) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> resize_op = vision::Resize({30, 30});
|
||||
std::shared_ptr<TensorTransform> resize_op(new vision::Resize({30, 30}));
|
||||
EXPECT_NE(resize_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -1586,10 +1586,10 @@ TEST_F(MindDataTestPipeline, TestTensorOpsAndMap) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> resize_op = vision::Resize({30, 30});
|
||||
std::shared_ptr<TensorTransform> resize_op(new vision::Resize({30, 30}));
|
||||
EXPECT_NE(resize_op, nullptr);
|
||||
|
||||
std::shared_ptr<TensorOperation> center_crop_op = vision::CenterCrop({16, 16});
|
||||
std::shared_ptr<TensorTransform> center_crop_op(new vision::CenterCrop({16, 16}));
|
||||
EXPECT_NE(center_crop_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
* Copyright 2020-2021 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.
|
||||
|
@ -43,7 +43,7 @@ TEST_F(MindDataTestPipeline, TestTFRecordDatasetBasic) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> random_horizontal_flip_op = vision::RandomHorizontalFlip(0.5);
|
||||
std::shared_ptr<TensorTransform> random_horizontal_flip_op = std::make_shared<vision::RandomHorizontalFlip>(0.5);
|
||||
EXPECT_NE(random_horizontal_flip_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -98,7 +98,7 @@ TEST_F(MindDataTestPipeline, TestTFRecordDatasetBasicGetters) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> random_horizontal_flip_op = vision::RandomHorizontalFlip(0.5);
|
||||
std::shared_ptr<TensorTransform> random_horizontal_flip_op = std::make_shared<vision::RandomHorizontalFlip>(0.5);
|
||||
EXPECT_NE(random_horizontal_flip_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
|
|
@ -35,7 +35,7 @@ TEST_F(MindDataTestPipeline, TestComposeSuccess) {
|
|||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, false, RandomSampler(false, 3));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
/* FIXME - Disable until proper external API for Compose is provided
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> compose = transforms::Compose({vision::Decode(), vision::Resize({777, 777})});
|
||||
EXPECT_NE(compose, nullptr);
|
||||
|
@ -69,11 +69,12 @@ TEST_F(MindDataTestPipeline, TestComposeSuccess) {
|
|||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestComposeFail) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestComposeFail with invalid transform.";
|
||||
|
||||
/* FIXME - Disable until proper external API for Compose is provided
|
||||
// Resize: Non-positive size value: -1 at element: 0
|
||||
// Compose: transform ops must not be null
|
||||
std::shared_ptr<TensorOperation> compose1 = transforms::Compose({vision::Decode(), vision::Resize({-1})});
|
||||
|
@ -86,6 +87,7 @@ TEST_F(MindDataTestPipeline, TestComposeFail) {
|
|||
// Compose: transform list must not be empty
|
||||
std::shared_ptr<TensorOperation> compose3 = transforms::Compose({});
|
||||
EXPECT_EQ(compose3, nullptr);
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestDuplicateSuccess) {
|
||||
|
@ -137,7 +139,7 @@ TEST_F(MindDataTestPipeline, TestOneHotSuccess1) {
|
|||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> hwc_to_chw = vision::HWC2CHW();
|
||||
std::shared_ptr<TensorTransform> hwc_to_chw = std::make_shared<vision::HWC2CHW>();
|
||||
EXPECT_NE(hwc_to_chw, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -157,8 +159,8 @@ TEST_F(MindDataTestPipeline, TestOneHotSuccess1) {
|
|||
ds = ds->Map({one_hot_op}, {"label"});
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
std::shared_ptr<TensorOperation> cutmix_batch_op =
|
||||
vision::CutMixBatch(mindspore::dataset::ImageBatchFormat::kNCHW, 1.0, 1.0);
|
||||
std::shared_ptr<TensorTransform> cutmix_batch_op =
|
||||
std::make_shared<vision::CutMixBatch>(mindspore::dataset::ImageBatchFormat::kNCHW, 1.0, 1.0);
|
||||
EXPECT_NE(cutmix_batch_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -215,7 +217,7 @@ TEST_F(MindDataTestPipeline, TestOneHotSuccess2) {
|
|||
ds = ds->Map({one_hot_op}, {"label"});
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
std::shared_ptr<TensorOperation> mixup_batch_op = vision::MixUpBatch(2.0);
|
||||
std::shared_ptr<TensorTransform> mixup_batch_op = std::make_shared<vision::MixUpBatch>(2.0);
|
||||
EXPECT_NE(mixup_batch_op, nullptr);
|
||||
|
||||
// Create a Map operation on ds
|
||||
|
@ -294,7 +296,7 @@ TEST_F(MindDataTestPipeline, TestRandomApplySuccess) {
|
|||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, RandomSampler(false, 5));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
/* FIXME - Disable until proper external API for RandomApply is provided
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> random_apply = transforms::RandomApply({vision::Resize({777, 777})}, 0.8);
|
||||
EXPECT_NE(random_apply, nullptr);
|
||||
|
@ -326,11 +328,12 @@ TEST_F(MindDataTestPipeline, TestRandomApplySuccess) {
|
|||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestRandomApplyFail) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomApplyFail with invalid transform.";
|
||||
|
||||
/* FIXME - Disable until proper external API for RandomApply is provided
|
||||
// Resize: Non-positive size value: -1 at element: 0
|
||||
// RandomApply: transform ops must not be null
|
||||
std::shared_ptr<TensorOperation> random_apply1 = transforms::RandomApply({vision::Decode(), vision::Resize({-1})});
|
||||
|
@ -347,6 +350,7 @@ TEST_F(MindDataTestPipeline, TestRandomApplyFail) {
|
|||
// RandomApply: Probability has to be between 0 and 1
|
||||
std::shared_ptr<TensorOperation> random_apply4 = transforms::RandomApply({vision::Resize({100})}, -1);
|
||||
EXPECT_EQ(random_apply4, nullptr);
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestRandomChoiceSuccess) {
|
||||
|
@ -356,7 +360,7 @@ TEST_F(MindDataTestPipeline, TestRandomChoiceSuccess) {
|
|||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, RandomSampler(false, 3));
|
||||
EXPECT_NE(ds, nullptr);
|
||||
|
||||
/* FIXME - Disable until proper external API for RandomChoice is provided
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> random_choice =
|
||||
transforms::RandomChoice({vision::Resize({777, 777}), vision::Resize({888, 888})});
|
||||
|
@ -389,11 +393,12 @@ TEST_F(MindDataTestPipeline, TestRandomChoiceSuccess) {
|
|||
|
||||
// Manually terminate the pipeline
|
||||
iter->Stop();
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestRandomChoiceFail) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomChoiceFail with invalid transform.";
|
||||
|
||||
/* FIXME - Disable until proper external API for RandomChoice is provided
|
||||
// Resize: Non-positive size value: -1 at element: 0
|
||||
// RandomChoice: transform ops must not be null
|
||||
std::shared_ptr<TensorOperation> random_choice1 = transforms::RandomChoice({vision::Decode(), vision::Resize({-1})});
|
||||
|
@ -406,6 +411,7 @@ TEST_F(MindDataTestPipeline, TestRandomChoiceFail) {
|
|||
// RandomChoice: transform list must not be empty
|
||||
std::shared_ptr<TensorOperation> random_choice3 = transforms::RandomChoice({});
|
||||
EXPECT_EQ(random_choice3, nullptr);
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestPipeline, TestTypeCastSuccess) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
* Copyright 2020-2021 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.
|
||||
|
@ -22,9 +22,9 @@
|
|||
#include "utils/log_adapter.h"
|
||||
|
||||
using namespace mindspore::dataset;
|
||||
using mindspore::MsLogLevel::INFO;
|
||||
using mindspore::ExceptionType::NoExceptionType;
|
||||
using mindspore::LogStream;
|
||||
using mindspore::ExceptionType::NoExceptionType;
|
||||
using mindspore::MsLogLevel::INFO;
|
||||
|
||||
class MindDataTestExecute : public UT::CVOP::CVOpCommon {
|
||||
protected:
|
||||
|
@ -41,9 +41,9 @@ TEST_F(MindDataTestExecute, TestComposeTransforms) {
|
|||
auto image = mindspore::MSTensor(std::make_shared<DETensor>(de_tensor));
|
||||
|
||||
// Transform params
|
||||
std::shared_ptr<TensorOperation> decode = vision::Decode();
|
||||
std::shared_ptr<TensorOperation> center_crop = vision::CenterCrop({30});
|
||||
std::shared_ptr<TensorOperation> rescale = vision::Rescale(1./3, 0.5);
|
||||
std::shared_ptr<TensorTransform> decode = std::make_shared<vision::Decode>();
|
||||
std::shared_ptr<TensorTransform> center_crop(new vision::CenterCrop({30}));
|
||||
std::shared_ptr<TensorTransform> rescale = std::make_shared<vision::Rescale>(1. / 3, 0.5);
|
||||
|
||||
auto transform = Execute({decode, center_crop, rescale});
|
||||
Status rc = transform(image, &image);
|
||||
|
@ -52,3 +52,132 @@ TEST_F(MindDataTestExecute, TestComposeTransforms) {
|
|||
EXPECT_EQ(30, image.Shape()[0]);
|
||||
EXPECT_EQ(30, image.Shape()[1]);
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestExecute, TestTransformInput1) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestExecute-TestTransformInput1.";
|
||||
// Test Execute with transform op input using API constructors, with std::shared_ptr<TensorTransform pointers,
|
||||
// instantiated via mix of make_shared and new
|
||||
|
||||
// Read images
|
||||
std::shared_ptr<mindspore::dataset::Tensor> de_tensor;
|
||||
mindspore::dataset::Tensor::CreateFromFile("data/dataset/apple.jpg", &de_tensor);
|
||||
auto image = mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_tensor));
|
||||
|
||||
// Define transform operations
|
||||
std::shared_ptr<TensorTransform> decode = std::make_shared<vision::Decode>();
|
||||
std::shared_ptr<TensorTransform> resize(new vision::Resize({224, 224}));
|
||||
std::shared_ptr<TensorTransform> normalize(
|
||||
new vision::Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}));
|
||||
std::shared_ptr<TensorTransform> hwc2chw = std::make_shared<vision::HWC2CHW>();
|
||||
|
||||
mindspore::dataset::Execute Transform({decode, resize, normalize, hwc2chw});
|
||||
|
||||
// Apply transform on image
|
||||
Status rc = Transform(image, &image);
|
||||
|
||||
// Check image info
|
||||
ASSERT_TRUE(rc.IsOk());
|
||||
ASSERT_EQ(image.Shape().size(), 3);
|
||||
ASSERT_EQ(image.Shape()[0], 3);
|
||||
ASSERT_EQ(image.Shape()[1], 224);
|
||||
ASSERT_EQ(image.Shape()[2], 224);
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestExecute, TestTransformInput2) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestExecute-TestTransformInput2.";
|
||||
// Test Execute with transform op input using API constructors, with std::shared_ptr<TensorTransform pointers,
|
||||
// instantiated via new
|
||||
|
||||
// Read images
|
||||
std::shared_ptr<mindspore::dataset::Tensor> de_tensor;
|
||||
mindspore::dataset::Tensor::CreateFromFile("data/dataset/apple.jpg", &de_tensor);
|
||||
auto image = mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_tensor));
|
||||
|
||||
// Define transform operations
|
||||
std::shared_ptr<TensorTransform> decode(new vision::Decode());
|
||||
std::shared_ptr<TensorTransform> resize(new vision::Resize({224, 224}));
|
||||
std::shared_ptr<TensorTransform> normalize(
|
||||
new vision::Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}));
|
||||
std::shared_ptr<TensorTransform> hwc2chw(new vision::HWC2CHW());
|
||||
|
||||
mindspore::dataset::Execute Transform({decode, resize, normalize, hwc2chw});
|
||||
|
||||
// Apply transform on image
|
||||
Status rc = Transform(image, &image);
|
||||
|
||||
// Check image info
|
||||
ASSERT_TRUE(rc.IsOk());
|
||||
ASSERT_EQ(image.Shape().size(), 3);
|
||||
ASSERT_EQ(image.Shape()[0], 3);
|
||||
ASSERT_EQ(image.Shape()[1], 224);
|
||||
ASSERT_EQ(image.Shape()[2], 224);
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestExecute, TestTransformInput3) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestExecute-TestTransformInput3.";
|
||||
// Test Execute with transform op input using API constructors, with auto pointers
|
||||
|
||||
// Read image
|
||||
std::shared_ptr<mindspore::dataset::Tensor> de_tensor;
|
||||
mindspore::dataset::Tensor::CreateFromFile("data/dataset/apple.jpg", &de_tensor);
|
||||
auto image = mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_tensor));
|
||||
|
||||
// Define transform operations
|
||||
auto decode(new vision::Decode()); // auto will create raw pointer to Decode class
|
||||
auto resize(new vision::Resize({224, 224}));
|
||||
auto normalize(
|
||||
new vision::Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}));
|
||||
auto hwc2chw(new vision::HWC2CHW());
|
||||
|
||||
std::vector<TensorTransform *> op_list = {decode, resize, normalize, hwc2chw};
|
||||
mindspore::dataset::Execute Transform(op_list);
|
||||
|
||||
// Apply transform on image
|
||||
Status rc = Transform(image, &image);
|
||||
|
||||
// Check image info
|
||||
ASSERT_TRUE(rc.IsOk());
|
||||
ASSERT_EQ(image.Shape().size(), 3);
|
||||
ASSERT_EQ(image.Shape()[0], 3);
|
||||
ASSERT_EQ(image.Shape()[1], 224);
|
||||
ASSERT_EQ(image.Shape()[2], 224);
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestExecute, TestTransformInputSequential) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestExecute-TestTransformInputSequential.";
|
||||
// Test Execute with transform op input using API constructors, with auto pointers;
|
||||
// Apply 2 transformations sequentially, including single non-vector Transform op input
|
||||
|
||||
// Read images
|
||||
std::shared_ptr<mindspore::dataset::Tensor> de_tensor;
|
||||
mindspore::dataset::Tensor::CreateFromFile("data/dataset/apple.jpg", &de_tensor);
|
||||
auto image = mindspore::MSTensor(std::make_shared<mindspore::dataset::DETensor>(de_tensor));
|
||||
|
||||
// Define transform#1 operations
|
||||
auto decode(new vision::Decode()); // auto will create raw pointer to Decode class
|
||||
auto resize(new vision::Resize({224, 224}));
|
||||
auto normalize(
|
||||
new vision::Normalize({0.485 * 255, 0.456 * 255, 0.406 * 255}, {0.229 * 255, 0.224 * 255, 0.225 * 255}));
|
||||
|
||||
std::vector<TensorTransform *> op_list = {decode, resize, normalize};
|
||||
mindspore::dataset::Execute Transform(op_list);
|
||||
|
||||
// Apply transform#1 on image
|
||||
Status rc = Transform(image, &image);
|
||||
|
||||
// Define transform#2 operations
|
||||
auto hwc2chw(new vision::HWC2CHW());
|
||||
|
||||
TensorTransform *op_single = hwc2chw;
|
||||
mindspore::dataset::Execute Transform2(op_single);
|
||||
|
||||
// Apply transform#2 on image
|
||||
rc = Transform2(image, &image);
|
||||
|
||||
// Check image info
|
||||
ASSERT_TRUE(rc.IsOk());
|
||||
ASSERT_EQ(image.Shape().size(), 3);
|
||||
ASSERT_EQ(image.Shape()[0], 3);
|
||||
ASSERT_EQ(image.Shape()[1], 224);
|
||||
ASSERT_EQ(image.Shape()[2], 224);
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ TEST_F(MindDataTestTensorOpFusionPass, RandomCropDecodeResizeDisabled) {
|
|||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, false, SequentialSampler(0, 11));
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> decode = vision::Decode();
|
||||
std::shared_ptr<TensorOperation> random_resized_crop = vision::RandomResizedCrop({5});
|
||||
std::shared_ptr<TensorTransform> decode(new vision::Decode());
|
||||
std::shared_ptr<TensorTransform> random_resized_crop(new vision::RandomResizedCrop({5}));
|
||||
ds = ds->Map({decode, random_resized_crop}, {"image"});
|
||||
|
||||
std::shared_ptr<DatasetNode> node = ds->IRNode();
|
||||
|
@ -70,8 +70,8 @@ TEST_F(MindDataTestTensorOpFusionPass, RandomCropDecodeResizeEnabled) {
|
|||
std::shared_ptr<Dataset> ds = ImageFolder(folder_path, false, SequentialSampler(0, 11));
|
||||
|
||||
// Create objects for the tensor ops
|
||||
std::shared_ptr<TensorOperation> decode = vision::Decode();
|
||||
std::shared_ptr<TensorOperation> random_resized_crop = vision::RandomResizedCrop({5});
|
||||
std::shared_ptr<TensorTransform> decode(new vision::Decode());
|
||||
std::shared_ptr<TensorTransform> random_resized_crop(new vision::RandomResizedCrop({5}));
|
||||
ds = ds->Map({decode, random_resized_crop}, {"image"});
|
||||
|
||||
std::shared_ptr<DatasetNode> node = ds->IRNode();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
* Copyright 2020-2021 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.
|
||||
|
@ -34,41 +34,44 @@ using mindspore::MsLogLevel::INFO;
|
|||
|
||||
class MindDataTestOptimizationPass : public UT::DatasetOpTesting {};
|
||||
|
||||
// TEST_F(MindDataTestOptimizationPass, MindDataTestAutoWorkerPass) {
|
||||
// MS_LOG(INFO) << "Doing MindDataTestOptimizationPass-MindDataTestAutoWorkerPass.";
|
||||
//
|
||||
// std::shared_ptr<SchemaObj> schema = std::make_shared<SchemaObj>();
|
||||
// ASSERT_TRUE(schema->add_column("label", "uint32", {}));
|
||||
// std::shared_ptr<Dataset> map_leaf = ImageFolder("dir")->SetNumWorkers(0);
|
||||
// std::shared_ptr<Dataset> nonmap_leaf = RandomData(44, schema)->SetNumWorkers(0);
|
||||
// std::shared_ptr<Dataset> batch = Zip({map_leaf, nonmap_leaf})->Batch(1)->SetNumWorkers(0);
|
||||
// std::shared_ptr<Dataset> map = batch->Map({})->SetNumWorkers(0);
|
||||
// // {ImageFolder, RandomData} -> zip -> batch
|
||||
// EXPECT_EQ(map_leaf->IRNode()->num_workers(), 0);
|
||||
// EXPECT_EQ(nonmap_leaf->IRNode()->num_workers(), 0);
|
||||
// EXPECT_EQ(batch->IRNode()->num_workers(), 0);
|
||||
// EXPECT_EQ(map->IRNode()->num_workers(), 0);
|
||||
//
|
||||
// std::unique_ptr<IRPass> pass = std::make_unique<AutoWorkerPass>();
|
||||
// bool m = false;
|
||||
// ASSERT_OK(pass->Run(map->IRNode(), &m));
|
||||
//
|
||||
// // checking that after this pass, num_workers are set correctly (aka a positive number)
|
||||
// // It is hard to test a exact value because num_threads are different for different machine
|
||||
// // however, this will for sure succeed bc regardless of the total threads on cpu, this would always be >= 1
|
||||
// EXPECT_NE(map_leaf->IRNode()->num_workers(), 0);
|
||||
// EXPECT_NE(nonmap_leaf->IRNode()->num_workers(), 0);
|
||||
// EXPECT_NE(batch->IRNode()->num_workers(), 0);
|
||||
// EXPECT_NE(map->IRNode()->num_workers(), 0);
|
||||
// MS_LOG(DEBUG) << map_leaf->IRNode()->Name() << ": num_worker=" << map_leaf->IRNode()->num_workers();
|
||||
// MS_LOG(DEBUG) << nonmap_leaf->IRNode()->Name() << ": num_worker=" << nonmap_leaf->IRNode()->num_workers();
|
||||
// MS_LOG(DEBUG) << batch->IRNode()->Name() << ": num_worker=" << batch->IRNode()->num_workers();
|
||||
// MS_LOG(DEBUG) << map->IRNode()->Name() << ": num_worker=" << map->IRNode()->num_workers();
|
||||
//}
|
||||
TEST_F(MindDataTestOptimizationPass, MindDataTestAutoWorkerPass) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestOptimizationPass-MindDataTestAutoWorkerPass.";
|
||||
|
||||
std::shared_ptr<SchemaObj> schema = std::make_shared<SchemaObj>();
|
||||
ASSERT_TRUE(schema->add_column("label", "uint32", {}));
|
||||
std::shared_ptr<Dataset> map_leaf = ImageFolder("dir")->SetNumWorkers(0);
|
||||
std::shared_ptr<Dataset> nonmap_leaf = RandomData(44, schema)->SetNumWorkers(0);
|
||||
std::shared_ptr<Dataset> batch = Zip({map_leaf, nonmap_leaf})->Batch(1)->SetNumWorkers(0);
|
||||
/* FIXME - Will uncomment out when full external API support is provided
|
||||
std::shared_ptr<Dataset> map = batch->Map({})->SetNumWorkers(0);
|
||||
// {ImageFolder, RandomData} -> zip -> batch
|
||||
EXPECT_EQ(map_leaf->IRNode()->num_workers(), 0);
|
||||
EXPECT_EQ(nonmap_leaf->IRNode()->num_workers(), 0);
|
||||
EXPECT_EQ(batch->IRNode()->num_workers(), 0);
|
||||
EXPECT_EQ(map->IRNode()->num_workers(), 0);
|
||||
|
||||
std::unique_ptr<IRPass> pass = std::make_unique<AutoWorkerPass>();
|
||||
bool m = false;
|
||||
ASSERT_OK(pass->Run(map->IRNode(), &m));
|
||||
|
||||
// checking that after this pass, num_workers are set correctly (aka a positive number)
|
||||
// It is hard to test a exact value because num_threads are different for different machine
|
||||
// however, this will for sure succeed bc regardless of the total threads on cpu, this would always be >= 1
|
||||
EXPECT_NE(map_leaf->IRNode()->num_workers(), 0);
|
||||
EXPECT_NE(nonmap_leaf->IRNode()->num_workers(), 0);
|
||||
EXPECT_NE(batch->IRNode()->num_workers(), 0);
|
||||
EXPECT_NE(map->IRNode()->num_workers(), 0);
|
||||
MS_LOG(DEBUG) << map_leaf->IRNode()->Name() << ": num_worker=" << map_leaf->IRNode()->num_workers();
|
||||
MS_LOG(DEBUG) << nonmap_leaf->IRNode()->Name() << ": num_worker=" << nonmap_leaf->IRNode()->num_workers();
|
||||
MS_LOG(DEBUG) << batch->IRNode()->Name() << ": num_worker=" << batch->IRNode()->num_workers();
|
||||
MS_LOG(DEBUG) << map->IRNode()->Name() << ": num_worker=" << map->IRNode()->num_workers();
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestOptimizationPass, MindDataTestTensorFusionPass) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestOptimizationPass-MindDataTestTensorFusionPass.";
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
/* FIXME - Will uncomment out when full external API support is provided
|
||||
std::shared_ptr<Dataset> root =
|
||||
ImageFolder(folder_path, false)->Map({vision::Decode(), vision::RandomResizedCrop({100})}, {"image"});
|
||||
|
||||
|
@ -82,11 +85,13 @@ TEST_F(MindDataTestOptimizationPass, MindDataTestTensorFusionPass) {
|
|||
auto fused_ops = map_node->operations();
|
||||
ASSERT_EQ(fused_ops.size(), 1);
|
||||
ASSERT_EQ(fused_ops[0]->Name(), vision::kRandomCropDecodeResizeOperation);
|
||||
*/
|
||||
}
|
||||
|
||||
TEST_F(MindDataTestOptimizationPass, MindDataTestTensorFusionPassPreBuiltTensorOperation) {
|
||||
MS_LOG(INFO) << "Doing MindDataTestOptimizationPass-MindDataTestTensorFusionPassPreBuiltTensorOperation.";
|
||||
std::string folder_path = datasets_root_path_ + "/testPK/data/";
|
||||
/* FIXME - Will uncomment out when full external API support is provided
|
||||
// make prebuilt tensor operation
|
||||
auto decode = std::make_shared<transforms::PreBuiltOperation>(vision::Decode()->Build());
|
||||
auto resize = std::make_shared<transforms::PreBuiltOperation>(vision::RandomResizedCrop({100})->Build());
|
||||
|
@ -102,4 +107,5 @@ TEST_F(MindDataTestOptimizationPass, MindDataTestTensorFusionPassPreBuiltTensorO
|
|||
auto fused_ops = map_node->operations();
|
||||
ASSERT_EQ(fused_ops.size(), 1);
|
||||
ASSERT_EQ(fused_ops[0]->Name(), kRandomCropDecodeResizeOp);
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue