The plugin framework provided by Vision SDK defines how to generate standard plugins to implement data interconnection between plugins and set plugin properties. Vision SDK supports single-input, single-output, multi-input, and multi-output plugins.
|
Member Function |
Description |
|---|---|
|
Init() |
This API is called only once to obtain configuration parameters and initialize service logic (for example, allocate reusable memory in the plugin). |
|
DeInit() |
This API is called only once to deinitialize a job (for example, releasing the memory). |
|
Process() |
This API is driven by data and is used to receive data from upstream plugins and send results to the output port after the service processing logic of users is completed. |
|
Common Attribute |
Description |
|---|---|
|
status_ |
Specifies whether the plugin runs in synchronous or asynchronous mode. The value is of the int type and the value range is [0, 1]. The value 0 (default) indicates asynchronous execution, and the value 1 indicates synchronous execution. Set the value as required. |
|
deviceId_ |
Specifies the processor on which the plugin runs. The value is of the int type and is the same as the value of deviceId at the beginning of the pipeline configuration file, by default. Set the value as required. |
|
dataSource_ |
Specifies the source of the data processed by the plugin. The value is of the string type and defaults to auto. You can specify the upstream plugin name as the data source. Set the value as required. |
Rewrite the DefineProperties function and register customized properties as follows:
1 2 3 4 |
std::vector<std::shared_ptr<void>> properties; std::shared_ptr<ElementProperty<string>> outputResizeHeight(new ElementProperty<string> {STRING, "resizeHeight", "resizeHeight", "the height of the resized output image", 640, 6, 4096}); properties.push_back(parentNameSptr); return properties; |
1 2 3 4 5 6 7 8 9 10 |
template<class T> struct ElementProperty { PropertyType type; // Property data type. The type can be string, int, uint, float, double, long, ulong. std::string name; // Property name, which is used to obtain the property value. For details, see the section about obtaining the property value. std::string nickName; // Property alias. This field is reserved. std::string desc; // Property description, which describes the function of the property. T defaultValue; // Default value of the property. T min; // Minimum value of the property. Set this field as required. For example, if the data of the string type does not have a minimum value, set this field to NULL. T max; // Maximum value of the property. Set this field as required. For example, if the data of the string type does not have a maximum value, set this field to NULL. }; |
In the Init() function, the property values corresponding to the plugin are transferred through the configParamMap input parameter and can be obtained based on the property name.
1 2 |
std::shared_ptr<string> outputResizeHeight = std::static_pointer_cast<string>(configParamMap["resizeHeight"]); std::string parentName = *outputResizeHeight.get(); |
The input and output ports of the plugin are used to receive input data and send output results, respectively. Multiple input and output ports can be registered for the plugin (see Creating MIMO Plugin Ports).
The port type can be static or dynamic (see Creating Dynamic Ports). A static port is generated after an element is created, and it must be connected. Otherwise, the stream fails to be created. The number of dynamic ports is variable, and they can be created as required.
The customized string must start with a letter and can contain letters, digits, and underscores (_). You are advised to name ports in the format of level-1 category/level-2 category, for example, image/yuv.
1 2 3 4 5 6 7 |
MxpiPortInfo MxPluginBase::DefineInputPorts() { MxpiPortInfo defaultInputPortInfo; std::vector<std::vector<std::string>> value = {{"ANY"}}; GenerateStaticInputPortsInfo(value, defaultInputPortInfo); return defaultInputPortInfo; } |
1 2 3 4 5 6 7 |
MxpiPortInfo MpModelInfer::DefineInputPorts() { MxpiPortInfo inputPortInfo; std::vector<std::vector<std::string>> value = {{"image/yuv"}}; GenerateStaticInputPortsInfo(value, inputPortInfo); return inputPortInfo; } |
The port formats used by the developed plugins are listed in Table 3:
|
Port |
Type |
|---|---|
|
Original image |
image/jpeg |
|
Video |
video/x-h264 |
|
Decoded image |
image/yuv image/rgb |
|
Bounding box |
metadata/object |
|
Image class |
metadata/class |
|
Image attribute |
metadata/attribute |
|
Image feature |
metadata/feature-vector |
|
Tensor |
metadata/tensor |
|
Drawing unit |
metadata/osd |
|
Semantic segmentation pixel |
metadata/semanticseg |
|
Text |
metadata/texts |
|
Key object point |
metadata/keypoint |
|
Result of serialization |
result/json-result |
|
Compatible with any port formats |
ANY. Data in any format can be matched. That is, the port can be connected to any port. |
|
Plugin |
Input |
Output |
Description |
|---|---|---|---|
|
mxpi_imagedecoder |
image/jpeg |
image/yuv, image/rgb, metadata/object |
Image decoding. metadata/object is supported in block division mode. |
|
mxpi_videodecoder |
video/x-h264 |
image/yuv, image/rgb |
Video decoding. |
|
mxpi_imageresize |
image/yuv, image/rgb, metadata/object |
image/yuv, image/rgb |
Image resizing |
|
mxpi_tensorinfer |
metadata/tensor or image/yuv |
metadata/tensor |
Tensor inference. Input tensors or images and output tensors. |
|
mxpi_modelinfer |
image/yuv |
metadata/object, metadata/class, metadata/attribute, metadata/feature-vector, metadata/tensor |
Image inference. The postprocessing result varies depending on the model: object bounding box, attribute, or feature. If postprocessing is not used, the inference result is directly output. |
|
mxpi_imagecrop |
metadata/objectbox |
image/yuv, image/rgb |
Image cropping |
|
mxpi_dataserialize |
ANY |
result/json-result |
Serialized into a JSON string. |
1
|
MX_PLUGIN_GENERATE(CustomPlugin) // Register a custom plugin using macro. |
1 2 |
set(PLUGIN_NAME "mxpi_customplugin") add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}") |
You can add multiple input ports or output ports during plugin development. To develop a MIMO plugin, perform the following steps:
status in the pipeline indicates processing mode. 0 (default) indicates asynchronous processing, and 1 indicates synchronous processing.
1 2 3 4 5 6 7 |
MxpiPortInfo MpModelInfer::DefineInputPorts() { MxpiPortInfo inputPortInfo; std::vector<std::vector<std::string>> value = {{"image/yuv"},{"image/yuv"}}; GenerateStaticInputPortsInfo(value, inputPortInfo); return inputPortInfo; } |
Modify portNum of the output API DefineOutputPorts of the plugin. The following uses the inference plugin as an example to describe how to set the output to two ports.
1 2 3 4 5 6 7 8 9 10 |
MxpiPortInfo MpModelInfer::DefineOutputPorts() { MxpiPortInfo outputPortInfo; std::vector<std::vector<std::string>> value = { {"metadata/object", "metadata/class", "metadata/attribute", "metadata/feature-vector", "metadata/tensor"}, {"metadata/object", "metadata/class", "metadata/attribute", "metadata/feature-vector", "metadata/tensor"} }; GenerateStaticOutputPortsInfo(value, outputPortInfo); return outputPortInfo; } |
Dynamic ports apply to the scenario where the amount of input or output data is variable, for example, the synchronization plugin mxpi_synchronize. You can configure the amount of input data to be synchronized. The number of dynamic ports is variable. You can create dynamic ports by editing the pipeline configuration file as required.
As shown in Figure 4, the synchronization plugin can create two or three input ports. The corresponding content of the pipeline configuration file is on the right of the figure.