Get started

You are viewing an old version of the documentation. You can switch to the documentation of the latest version by clicking the top-right corner of the page.

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.

  • Connect the license dongle provided by Mech-Mind to your device.

  • Make sure that CodeMeter is running: In the system tray, check if the CodeMeter icon installation codemeter icon is displayed in the Windows tray.

If you have installed Mech-DLK on your device, you don’t have to install CodeMeter again because it’s already in place. Check the Windows tray to make sure that CodeMeter is running.

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.

Create an input image

Call the following function to create an input image.

  • C#

  • C

MMindImage image = new MMindImage();
image.CreateFromPath("path/to/image.png");
List<MMindImage> images = new List<MMindImage> { image };
MMindImage input;
createImage("path/to/image.png", &input);

Create an inference engine

Call the following function to create an inference engine.

  • C#

  • C

InferEngine inferEngine = new InferEngine();
inferEngine.Create("path/to/xxx.dlkpack", BackendType.GpuDefault, 0);
  • If NVIDIA discrete graphics cards are available on your device, you can set the inference backend, i.e., the second parameter in the function, to GpuDefault or GpuOptimization.

    • When the inference backend is set to GpuOptimization, you need to wait for one to five minutes for model optimization.

  • If NVIDIA discrete graphics cards are unavailable on your device, you can only set the inference backend to CPU.

  • In this function, the third parameter represents the ID of the used NVIDIA graphics cards, which is 0 when there is only one graphics card. When the inference backend is set to CPU, this parameter is invalid.

Engine engine;
createPackInferEngine(&engine, "path/to/xxx.dlkpack", GpuDefault, 0);
  • If NVIDIA discrete graphics cards are available on your device, you can set the inference backend, i.e., the third parameter in the function, to GpuDefault or GpuOptimization.

    • When the inference backend is set to GpuOptimization, you need to wait for one to five minutes for model optimization.

  • If NVIDIA discrete graphics cards are unavailable on your device, you can only set the inference backend to CPU.

  • In this function, the fourth parameter represents the ID of the used NVIDIA graphics cards, which is 0 when there is only one graphics card. When the inference backend is set to CPU, this parameter is invalid.

Deep learning engine inference

Call the function below for deep learning engine inference.

  • C#

  • C

inferEngine.Infer(images);
infer(&engine, &input, 1);
In this function, the parameter 1 denotes the number of images for inference, which should equal the number of images in input.

Obtain the defect segmentation result

Call the function below to obtain the defect segmentation result.

  • C#

  • C

List<Result> results;
inferEngine.GetResults(out results);
DefectAndEdgeResult* defectAndEdgeResult = NULL;
unsigned int resultNum = 0;
getDefectSegmentataionResult(&engine, 0, &defectAndEdgeResult, &resultNum);

In this function, the second parameter 0 denotes the model index in the deep learning model inference package.

  • If the inference package is of a single model, the parameter can only be set to 0.

  • If the inference package is of cascaded models, the parameter should be set according to the order of modules in the model inference package.

Result visualization

Call the function below to visualize the model inference result.

  • C#

  • C

inferEngine.ResultVisualization(images);
image.Show("result");
resultVisualization(&engine, &input, 1);
showImage(&input, "result");
In this function, the parameter 1 denotes the number of images for inference, which should equal the number of images in input.

Release memory

Call the following function(s) to release memory and prevent memory leaks.

  • C#

  • C

inferEngine.Release();
releaseDefectSegmentationResult(&defectAndEdgeResult, resultNum);
releaseImage(&input);
releasePackInferEngine(&engine);

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.