Get Started

You are currently viewing the documentation for the latest version (3.0.0). To access a different version, click the "Switch version" button located in the upper-right corner of the page.

■ If you are not sure which version of the product you are currently using, please feel free to contact Mech-Mind Technical Support.

This chapter introduces how to apply Mech-DLK SDK to achieve inference using a defect segmentation model exported from Mech-DLK.

Prerequisites

  • Install Mech-DLK SDK.

  • Download and install the Sentinel LDK encryption driver. After installation, ensure that the encryption driver appears in Settings  Apps  Apps & features on the IPC.

    If you have installed Mech-DLK on your device, you do not need to install the encryption driver again because it is already in place.
  • Obtain and manage the software license.

Inference Flow

inference flow

Function Description

In this section, we take the Defect Segmentation model exported from Mech-DLK as an example to show the functions you need to use when using Mech-DLK SDK for model inference.

Starting from Mech-DLK SDK 3.0.0, C interfaces are no longer supported. The following example contains only C#, C++, and Python.

Create an Input Image

Call the following function to create an input image.

  • C#

  • C++

  • Python

MMindImage image = new MMindImage();
StatusCode status = image.CreateFromPath("path/to/image.png");
List<MMindImage> images = new List<MMindImage> { image };
mmind::dl::MMindImage image;
image.createFromPath("path/to/image.png");
std::vector<mmind::dl::MMindImage> images = {image};
import mmind_dl_sdk as mmind

image = mmind.MMindImage()
status = image.create_from_path("path/to/image.png")
images = [image]

Create an Inference Engine

Call the following function to create an inference engine.

  • C#

  • C++

  • Python

MMindInferEngine engine = new MMindInferEngine();
engine.Create("path/to/xxx.dlkpack");
StatusCode status = engine.Load();

In the Mech-DLK SDK C# interface, only the model path parameter is required for Create. After Load is called, the inference can be performed.

mmind::dl::MMindInferEngine engine;
engine.create(L"path/to/xxx.dlkpack");
// engine.setInferDeviceType(mmind::dl::InferDeviceType::GPUDefault);
// engine.setDeviceId(0);
// engine.setBatchSize("DefectSegmentation_0", 1);
// engine.setFloatPrecision("DefectSegmentation_0", mmind::dl::PrecisionType::FP32);
engine.load();

In C++ interfaces, the model parameters can be set according to the actual situation:

  • When the setxxx function is not called, by default, BatchSize is set to 1; PrecisionType is set to FP32; DeviceId is set to 0.

  • If you need to change the parameters of the inference engine, the setxxx function must be placed ahead of the load() function.

  • setBatchSize and setFloatPrecision need to specify module names (such as DefectSegmentation_0).

  • When InferDeviceType is first set to GPUOptimization for inference, model optimization is required and takes approximately 1–10 minutes.

engine = mmind.MMindInferEngine()
engine.create("path/to/xxx.dlkpack")
status = engine.load()

In the Python interface, only the model path parameter is needed for Create. After load() is called, inference can be performed.

Deep Learning Engine Inference

Call the function below for deep learning engine inference.

  • C#

  • C++

  • Python

engine.Infer(images);
engine.infer(images);
status = engine.infer(images)

Obtain the Defect Segmentation Result

Call the function below to obtain the defect segmentation result.

  • C#

  • C++

  • Python

List<MMindResult> results;
engine.GetModuleResult("DefectSegmentation_0", out results);
std::vector<mmind::dl::MMindResult> results;
engine.getModuleResult("DefectSegmentation_0", results);
status, results = engine.get_module_result("DefectSegmentation_0")

GetModuleResult requires the module name to be passed in. Confirm the module name in the Module List returned by the interface before obtaining the result.

Visualize Result

Call the function below to visualize the model inference result.

  • C#

  • C++

  • Python

engine.ResultVisualization(images);
images[0].Show("result");
engine.resultVisualization(images);
images[0].show("result");
status, vis_images = engine.result_visualization(images)
vis_images[0].show("result")

Release Memory

Release memory and reduce memory usage.

  • C#

  • C++

  • Python

engine.Release();
engine.release();
engine.release()

Is this page helpful?

You can give a feedback in any of the following ways:

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.