mindspore::dataset
Execute
#include <execute.h>
// shared_ptr
Execute::Execute(std::shared_ptr<TensorTransform> op, MapTargetDevice deviceType, uint32_t device_id);
Execute::Execute(std::vector<std::shared_ptr<TensorTransform>> ops, MapTargetDevice deviceType, uint32_t device_id);
// normal pointer
Execute::Execute(std::reference_wrapper<TensorTransform> op, MapTargetDevice deviceType, uint32_t device_id);
Execute::Execute(std::vector<std::reference_wrapper<TensorTransform>> ops, MapTargetDevice deviceType, uint32_t device_id);
// reference_wrapper
Execute::Execute(TensorTransform *op, MapTargetDevice deviceType, uint32_t device_id);
Execute::Execute(std::vector<TensorTransform *> 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 whendeviceType = MapTargetDevice::kAscend310
.
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.
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 constructingexecute
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:
// Define dvpp transforms
std::vector<int32_t> crop_paras = {224, 224};
std::vector<int32_t> resize_paras = {256};
std::vector<float> mean = {0.485 * 255, 0.456 * 255, 0.406 * 255};
std::vector<float> std = {0.229 * 255, 0.224 * 255, 0.225 * 255};
std::shared_ptr<TensorTransform> decode(new vision::Decode());
std::shared_ptr<TensorTransform> resize(new vision::Resize(resize_paras));
std::shared_ptr<TensorTransform> centercrop(new vision::CenterCrop(crop_paras));
std::shared_ptr<TensorTransform> normalize(new vision::Normalize(mean, std));
std::vector<std::shared_ptr<TensorTransform>> trans_list = {decode, resize, centercrop, normalize};
mindspore::dataset::Execute Transform(trans_list, MapTargetDevice::kAscend310);
ResizeBilinear
#include <image_process.h>
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>
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>
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>
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>
bool SubStractMeanNormalize(const LiteMat &src, LiteMat &dst, const std::vector<float> &mean, const std::vector<float> &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>
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>
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>
bool Split(const LiteMat &src, std::vector<LiteMat> &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>
bool Merge(const std::vector<LiteMat> &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>
void Affine(LiteMat &src, LiteMat &out_img, double M[6], std::vector<size_t> 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.
void Affine(LiteMat &src, LiteMat &out_img, double M[6], std::vector<size_t> dsize, UINT8_C3 borderValue)
#include <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>
std::vector<std::vector<float>> 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>
void ConvertBoxes(std::vector<std::vector<float>> &boxes, std::vector<std::vector<float>> &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>
std::vector<int> ApplyNms(std::vector<std::vector<float>> &all_boxes, std::vector<float> &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>
LiteMat is a class that processes images.
Constructors & Destructors
LiteMat
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
~LiteMat()
Destructor of MindSpore dataset LiteMat.
Public Member Functions
Init
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
bool IsEmpty() const
A function to determine whether the object is empty.
Returns
Return true or false.
Release
void Release()
A function to release memory.
Public Attributes
data_ptr_
data_ptr_
A pointer to the address of the image.
elem_size_
elem_size_
An int value. Bytes of the element.
width_
width_
An int value. The width of the image.
height_
height_
An int value. The height of the image.
channel_
channel_
An int value. The number of channels of the image.
c_step_
c_step_
An int value. The product of width and height after alignment.
dims_
dims_
An int value. The dimensions of the image.
size_
size_
The memory size of the image.
data_type_
data_type_
The data type of the image.
ref_count_
ref_count_
A pointer to the address of the reference counter.
Subtract
#include <lite_mat.h>
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>
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>
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.