# mindspore::dataset [![View Source On Gitee](./_static/logo_source.png)](https://gitee.com/mindspore/docs/blob/r1.2/docs/api_cpp/source_en/dataset.md) ## Execute \#include <[execute.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/include/execute.h)> ```cpp // shared_ptr Execute::Execute(std::shared_ptr op, MapTargetDevice deviceType, uint32_t device_id); Execute::Execute(std::vector> ops, MapTargetDevice deviceType, uint32_t device_id); // normal pointer Execute::Execute(std::reference_wrapper op, MapTargetDevice deviceType, uint32_t device_id); Execute::Execute(std::vector> ops, MapTargetDevice deviceType, uint32_t device_id); // reference_wrapper Execute::Execute(TensorTransform *op, MapTargetDevice deviceType, uint32_t device_id); Execute::Execute(std::vector ops, MapTargetDevice deviceType, uint32_t device_id); ``` Transform(image, text)Transform operators in eager mode executor class. Multiple constructors are supported,include shared_ptr, normal pointer and reference_wrapper. - Parameters - `op`: Single transform operator. - `ops`: A list of transform operators. - `deviceType`: Runtime hardware. Options are: CPU, GPU and Ascend310. - `device_id`: Device id of runtime hardware, only valid when `deviceType = MapTargetDevice::kAscend310`. ```cpp Status operator()(const mindspore::MSTensor &input, mindspore::MSTensor *output); ``` Eager mode execution API. - Parameters - `input`: Tensor before transformations. - `output`: Tensor after transformations. - Returns Status code which indicate the execution result. ```cpp std::string Execute::AippCfgGenerator() ``` Aipp module config file generator, Aipp module binds with Dvpp module. This API takes effects on case `deviceType = kAscend310`, generates Aipp config file according to the parameters of operators defined in data pre-processing. - Parameters None. - Returns Return a string indicates the system path of Aipp config file. ## Dvpp Module Dvpp module is a hardware decoder embedded in Ascend 310 AI chip which has a better performance on image processing compare with CPU operators. Several transforms applied on JPEG format image are supported. - If let `deviceType = kAscend310` when constructing `execute` object, Dvpp operators will be applied during runtime. - Dvpp module supporting transforms list: `Decode(), Resize(), CenterCrop(), Normalize()`. - The above Dvpp operator and the CPU operator of the same function share a unified API, which is only distinguished by `deviceType`. Example: ```cpp // Define dvpp transforms std::vector crop_paras = {224, 224}; std::vector resize_paras = {256}; std::vector mean = {0.485 * 255, 0.456 * 255, 0.406 * 255}; std::vector std = {0.229 * 255, 0.224 * 255, 0.225 * 255}; std::shared_ptr decode(new vision::Decode()); std::shared_ptr resize(new vision::Resize(resize_paras)); std::shared_ptr centercrop(new vision::CenterCrop(crop_paras)); std::shared_ptr normalize(new vision::Normalize(mean, std)); std::vector> trans_list = {decode, resize, centercrop, normalize}; mindspore::dataset::Execute Transform(trans_list, MapTargetDevice::kAscend310); ``` ## ResizeBilinear \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp bool ResizeBilinear(LiteMat &src, LiteMat &dst, int dst_w, int dst_h) ``` Resize image by bilinear algorithm, currently the data type only supports uint8, the channel only supports 3 and 1. - Parameters - `src`: Input image data. - `dst`: Output image data. - `dst_w`: The width of the output image data. - `dst_h`: The height of the output image data. - Returns Return true if the execution is successful, otherwise return false if the condition is not met. ## InitFromPixel \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp bool InitFromPixel(const unsigned char *data, LPixelType pixel_type, LDataType data_type, int w, int h, LiteMat &m) ``` Initialize LiteMat from pixel, providing data in RGB or BGR format does not need to be converted. Currently the conversion supports RGB_TO_BGR, RGBA_To_RGB, RGBA_To_BGR, NV21_To_BGR and NV12_To_BGR. - Parameters - `data`: Input data. - `pixel_type`: The type of pixel. - `data_type`: The type of data. - `w`: The width of the output data. - `h`: The height of the output data. - `mat`: Used to store image data. - Returns Return true if the initialization is successful, otherwise return false. ## ConvertTo \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp bool ConvertTo(LiteMat &src, LiteMat &dst, double scale = 1.0) ``` Convert the data type, currently it supports converting the data type from uint8 to float. - Parameters - `src`: Input image data. - `dst`: Output image data. - `scale`: Scale pixel values (default: 1.0). - Returns Return true if the data type is converted successfully, otherwise return false. ## Crop \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp bool Crop(LiteMat &src, LiteMat &dst, int x, int y, int w, int h) ``` Crop image, the channel supports 3 and 1. - Parameters - `src`: Input image data. - `dst`: Output image data. - `x`: The x coordinate value of the starting point of the screenshot. - `y`: The y coordinate value of the starting point of the screenshot. - `w`: The width of the screenshot. - `h`: The height of the screenshot. - Returns Return true if the image is cropped successfully, otherwise return false. ## SubStractMeanNormalize \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp bool SubStractMeanNormalize(const LiteMat &src, LiteMat &dst, const std::vector &mean, const std::vector &std) ``` Normalize image, currently the supports data type is float. - Parameters - `src`: Input image data. - `dst`: Output image data. - `mean`: Mean of the data set. - `std`: Norm of the data set. - Returns Return true if the normalization is successful, otherwise return false. ## Pad \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp bool Pad(const LiteMat &src, LiteMat &dst, int top, int bottom, int left, int right, PaddBorderType pad_type, uint8_t fill_b_or_gray, uint8_t fill_g, uint8_t fill_r) ``` Pad image, the channel supports 3 and 1. - Parameters - `src`: Input image data. - `dst`: Output image data. - `top`: The length of top. - `bottom`: The length of bottom. - `left`: The length of left. - `right`: The length of right. - `pad_type`: The type of pad. - `fill_b_or_gray`: B or GRAY. - `fill_g`: G. - `fill_r`: R. - Returns Return true if the image is filled successfully, otherwise return false. ## ExtractChannel \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp bool ExtractChannel(const LiteMat &src, LiteMat &dst, int col) ``` Extract image channel by index. - Parameters - `src`: Input image data. - `col`: The serial number of the channel. - Returns Return true if the image channel is extracted successfully, otherwise return false. ## Split \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp bool Split(const LiteMat &src, std::vector &mv) ``` Split image channels to single channel. - Parameters - `src`: Input image data. - `mv`: Single channel data. - Returns Return true if the image channel is split successfully, otherwise return false. ## Merge \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp bool Merge(const std::vector &mv, LiteMat &dst) ``` Create a multi-channel image out of several single-channel arrays. - Parameters - `mv`: Single channel data. - `dst`: Output image data. - Returns Return true if the multi-channel image is created successfully, otherwise returns false. ## Affine \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp void Affine(LiteMat &src, LiteMat &out_img, double M[6], std::vector dsize, UINT8_C1 borderValue) ``` Apply affine transformation to the 1-channel image. - Parameters - `src`: Input image data. - `out_img`: Output image data. - `M[6]`: Affine transformation matrix. - `dsize`: The size of the output image. - `borderValue`: The pixel value is used for filing after the image is captured. ```cpp void Affine(LiteMat &src, LiteMat &out_img, double M[6], std::vector dsize, UINT8_C3 borderValue) ``` \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> Apply affine transformation to the 3-channel image. - Parameters - `src`: Input image data. - `out_img`: Output image data. - `M[6]`: Affine transformation matrix. - `dsize`: The size of the output image. - `borderValue`: The pixel value is used for filing after the image is captured. ## GetDefaultBoxes \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp std::vector> GetDefaultBoxes(BoxesConfig config) ``` Get default anchor boxes for Faster R-CNN, SSD, YOLO, etc. - Parameters - `config`: Objects of BoxesConfig structure. - Returns Return the default boxes. ## ConvertBoxes \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp void ConvertBoxes(std::vector> &boxes, std::vector> &default_boxes, BoxesConfig config) ``` Convert the prediction boxes to the actual boxes with (y, x, h, w). - Parameters - `boxes`: Actual size box. - `default_boxes`: Default box. - `config`: Objects of BoxesConfig structure. ## ApplyNms \#include <[image_process.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/image_process.h)> ```cpp std::vector ApplyNms(std::vector> &all_boxes, std::vector &all_scores, float thres, int max_boxes) ``` Real-size box non-maximum suppression. - Parameters - `all_boxes`: All input boxes. - `all_scores`: Score after all boxes are executed through the network. - `thres`: Pre-value of IOU. - `max_boxes`: Maximum value of output box. - Returns Return the id of the boxes. ## LiteMat \#include <[lite_mat.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.h)> LiteMat is a class that processes images. ### Constructors & Destructors #### LiteMat ```cpp LiteMat() LiteMat(int width, LDataType data_type = LDataType::UINT8) LiteMat(int width, int height, LDataType data_type = LDataType::UINT8) LiteMat(int width, int height, int channel, LDataType data_type = LDataType::UINT8) ``` Constructor of MindSpore dataset LiteMat using default value of parameters. #### ~LiteMat ```cpp ~LiteMat() ``` Destructor of MindSpore dataset LiteMat. ### Public Member Functions #### Init ```cpp void Init(int width, LDataType data_type = LDataType::UINT8) void Init(int width, int height, LDataType data_type = LDataType::UINT8) void Init(int width, int height, int channel, LDataType data_type = LDataType::UINT8) ``` The function to initialize the channel, width and height of the image, but the parameters are different. #### IsEmpty ```cpp bool IsEmpty() const ``` A function to determine whether the object is empty. - Returns Return true or false. #### Release ```cpp void Release() ``` A function to release memory. ### Public Attributes #### data_ptr_ ```cpp data_ptr_ ``` A **pointer** to the address of the image. #### elem_size_ ```cpp elem_size_ ``` An **int** value. Bytes of the element. #### width_ ```cpp width_ ``` An **int** value. The width of the image. #### height_ ```cpp height_ ``` An **int** value. The height of the image. #### channel_ ```cpp channel_ ``` An **int** value. The number of channels of the image. #### c_step_ ```cpp c_step_ ``` An **int** value. The product of width and height after alignment. #### dims_ ```cpp dims_ ``` An **int** value. The dimensions of the image. #### size_ ```cpp size_ ``` The memory size of the image. #### data_type_ ```cpp data_type_ ``` The data type of the image. #### ref_count_ ```cpp ref_count_ ``` A **pointer** to the address of the reference counter. ## Subtract \#include <[lite_mat.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.h)> ```cpp bool Subtract(const LiteMat &src_a, const LiteMat &src_b, LiteMat *dst) ``` Calculate the element difference between two images. - Parameters - `src_a`: Input image_a data. - `src_b`: Input image_b data. - `dst`: Output image data. - Returns Return true if the calculation satisfies the conditions, otherwise return false. ## Divide \#include <[lite_mat.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.h)> ```cpp bool Divide(const LiteMat &src_a, const LiteMat &src_b, LiteMat *dst) ``` Calculates the division between the two images for each element. - Parameters - `src_a`: Input image_a data. - `src_b`: Input image_b data. - `dst`: Output image data. - Returns Return true if the calculation satisfies the conditions, otherwise return false. ## Multiply \#include <[lite_mat.h](https://gitee.com/mindspore/mindspore/blob/r1.2/mindspore/ccsrc/minddata/dataset/kernels/image/lite_cv/lite_mat.h)> ```cpp bool Multiply(const LiteMat &src_a, const LiteMat &src_b, LiteMat *dst) ``` Calculates the multiply between the two images for each element. - Parameters - `src_a`: Input image_a data. - `src_b`: Input image_b data. - `dst`: Output image data. - Returns Return true if the calculation satisfies the conditions, otherwise return false.