API 更改日志

本主题列出以前 VisionPro Deep Learning 版本中的 API 更改。

VisionPro Deep Learning 4.0

介绍了工具参数和 API 函数

多类分割

引入了对多类分割关闭 分割是从图像中选择视图的过程。的支持。threshold参数已被弃用,现由 region_thresholds 参数替代。

C++ 参数(JSON 格式的字符串):

  • post_process_parameters/red/region_thresholds

  • post_process_parameters/red/region_colors

  • post_processing/red/region_thresholds

  • post_processing/red/region_colors

C# 参数:

  • region_thresholds

    • ViDi2.Training.IRedStandardParameters.RegionThresholds

    • ViDi2.Training.IRedToolParameters.RegionThresholds

    • ViDi2.Training.IAnomalyDetectionParameters.RegionThresholds

    • ViDi2.Runtime.IRedStandardParameters.RegionThresholds

    • ViDi2.Runtime.IRedToolParameters.RegionThresholds

    • ViDi2.Runtime.IAnomalyDetectionParameters.RegionThresholds

  • region_colors

    • ViDi2.Training.IRedStandardParameters.ClassColors

    • ViDi2.Training.IRedToolParameters.RegionColors

    • ViDi2.Training.IAnomalyDetectionParameters.RegionColors

    • ViDi2.Runtime.IRedStandardParameters.ClassColors

    • ViDi2.Runtime.IRedToolParameters.RegionColors

    • ViDi2.Runtime.IAnomalyDetectionParameters.RegionColors

训练热力图

训练关闭 训练是您的工具(神经网络)根据您的标注学习特征(像素)的过程。例如,工具将根据您绘制的缺陷/正常标注,学习每个图像中的缺陷/正常像素。工具训练的目标是充分学习,能够对未见过的图像是否缺陷给出正确的检测结果。训练的关键是确保将所有可能的变化都包括在训练集中,并且图像被正确标注。训练时间因应用程序、工具设置以及用于训练网络的 PC 中的 GPU 而异。 API 中引入了热力图支持。

  • C++ 参数:training_parameters/heat_map_on

  • C# 参数:ViDi2.Training.IGreenStandardParameters.HeatMapOn

异常值评分

引入了对训练 API 中异常值评分的支持。

  • C++ 参数:training_parameters/outlier_check_on

  • C# 参数:ViDi2.Training.IGreenStandardParameters.OutlierOn

加速训练

在训练 API 中引入了对加速训练选项的支持。

  • C++ 参数:training_parameters/accelerated_training

  • C# 参数:ViDi2.Training.IToolParametersStandard.AcceleratedTraining

异常值评分和运行时热力图的运行时导出选项

引入了用于异常值评分和运行时热力图的运行时导出选项。

C++ 函数:

  • vidi_training_export_runtime_workspace_to_memory2

  • vidi_training_export_runtime_workspace_to_file2

    在运行时要使用热力图或异常值评分时,请使用 export_option 参数来设置附加导出选项。

  • @param export_option:您必须提供一个 JSON 格式的字符串,为每个工具设置 outlier_check_onheat_map_on 标志。

C# 函数:

  • ViDi2.Training.IWorkspace.ExportRuntimeWorkspace

  • ViDi2.Training.IWorkspace.ExportRuntimeWorkspaceToFile

训练 API 中的 TensorRT 转换

引入了对训练和运行阶段 TensorRT 转换的支持。在训练 API 中使用此函数来运行 TensorRT 转换。所有参数与运行时 API 中的参数相同。

  • C++ 函数:vidi_training_tool_convert_trt

  • C# 函数:ViDi2.Training.ITool.OptimizeTensorRT

更改了工具参数和 API 函数

TensorRT 相关参数更改

将布尔参数 process_with_trt 替换为字符串参数 trt_mode,以引入 TensorRT 优化的 “int8” 选项。

C++参数:

  • runtime_parameters/trt_mode (string)

    • “无” 选项:不使用 TensorRT 优化。

    • “基本”选项:使用默认 TensorRT 优化。

    • “int8”选项:使用 int8 TensorRT 优化。

  • vidi_training_tool_convert_trt

  • vidi_runtime_tool_convert_trt

  • @param 模式参数:使用字符串格式的优化模式。

    • “基本”选项:与之前版本相同,但没有此参数。

    • “int8”选项:int8 TensorRT 优化模式。

C# 参数:

  • ViDi2.Training.IToolParametersStandard.TensorRTMode

  • ViDi2.Runtime.IToolParametersStandard.TensorRTMode

  • ViDi2.Training.ITool.OptimizeTensorRT

  • ViDi2.Runtime.ITool.OptimizeTensorRT

与工具分类更新相关的参数已更改

移除了 network_type 参数,并更改了 training_mode 参数。

C++参数:

  • training_parameters/training_mode (string)

    • “精确” 选项:与之前版本中的“标准”相同。

    • “快速”选项:与之前版本中的“快速”相同。

    • “稳健”选项:替换“适应”。参数“基本”"适应" 已被弃用。

    • “fewsample”选项:使用此选项以少量图像样本训练绿色分类工具。

  • vidi_training_calculate_max_buffer_size

    • “model_capacity”选项由于我们采用了新的工具分类,因此将其移除。

C# 参数: 

  • ViDi2.Training.IToolParametersStandard.Mode

  • ViDi2.Training.IGreenTool.CalculateMaxBuffSize

已弃用的功能

以下功能已被弃用:

  • 相似性

  • 增量

  • 适应

  • 运行时热力图

    热力图现在同时支持训练和运行时。要在运行时中使用热力图,请在 vidi_training_export_runtime_workspace_to_memory2vidi_training_export_runtime_workspace_to_file2 函数中使用 export_option 参数。

  • 增量学习

有关更多详细信息,请参阅 API 弃用的功能

已更新项目例程名称

由于工具的类型和模式发生变化,示例代码的名称在 VisionPro Deep Learning 3.3.0 和 4.0.0 版本之间也有所变化。

C# API 示例

路径:C:\ProgramData\Cognex\VisionPro Deep Learning\4.0\Examples\c#

过时名称 新名称
Example.Runtime.HDGreen.Console Example.Runtime.GreenStandard.Console
Example.Runtime.HDRed.Console Example.Runtime.RedStandard.Console
Example.Training.HDGreen.Console Example.Training.GreenStandard.Console
Example.Training.HDRed.Console Example.Training.RedStandard.Console
Example.Runtime.HDGreen.Batched.Console Example.Runtime.GreenStandard.Batched.Console
Example.Runtime.OptimizeHDTool.Console Example.Runtime.OptimizeStandardTool.Console

C API 示例

路径:C:\ProgramData\Cognex\VisionPro Deep Learning\4.0\Examples\c++

过时名称 新名称
Example.Runtime.HDGreen Example.Runtime.GreenStandard
Example.Runtime.HDRed Example.Runtime.RedStandard
Example.Training.HDGreen Example.Training.GreenStandard
Example.Training.HDRed Example.Training.RedStandard
Example.Runtime.HDGreen.Batched Example.Runtime.GreenStandard.Batched
Example.Runtime.OptimizeHDTool Example.Runtime.OptimizeStandardTool

VisionPro Deep Learning 3.3

已弃用 extra_large 容量

  • vidi_training.h vidi_training_tool_train2 C++ 函数中,extra_large 选项对 training_artifact_key 参数不再有效。

  • ViDi2.Training.IToolParametersHighDetail.NetworkModel C# 函数中,extra_large 选项不再有效。

已弃用 extra_small 容量

  • vidi_training.h vidi_training_tool_train2 C++ 函数中,extra_small 选项对 training_artifact_key 参数不再有效。

  • ViDi2.Training.IToolParametersHighDetail.NetworkModel C# 函数中,extra_small 选项不再有效。

已弃用 green_quickred_quick 工具类型

  • vidi_training.h vidi_runtime_set_parameter C++ 函数中,tool_type/green_quick 和 tool_type/red_quick 选项不再有效。

  • ViDi2.ITool.ToolType.GreenQuickHighDetailViDi2.ITool.ToolType.RedQuickHighDetail C# 函数属性不再有效,并将从将来的版本中删除。

已弃用 runtime_parameters 中的 use_patchcrop_prediction 参数

  • vidi_runtime.h vidi_runtime_set_parametervidi_runtime.h vidi.runtime_tool_set_parameter C++ 函数中,runtime_parameters/use_patchcrop_prediction 参数不再有效。

  • ViDi2.Training.IRedHighDetailParameters.UsePatchcropPredictionViDi2.Runtime.IRedHighDetailParameters.UsePatchcropPrediction C# 函数属性已移除。

已弃用 runtime_parameters 中的 max_downsampling_size 参数

  • vidi_runtime.h vidi_runtime_set_parametervidi_runtime.h vidi.runtime_tool_set_parameter C++ 函数中,runtime_parameters/max_downsampling_size 参数不再有效。

  • ViDi2.Training.IRedHighDetailParameters.MaxDownSamplingSizeViDi2.Runtime.IRedHighDetailParameters.MaxDownSamplingSize C# 函数属性已移除。

已弃用 training_parameters 中的 minimum_epochs 参数

  • vidi_training.h vidi_training_set_parametervidi_training.h vidi.training_tool_set_parameter C++ 函数中,training_parameters/minimum_epochs 参数不再有效。

  • ViDi2.Training.IToolParametersHighDetail.MinimumEpochs C# 函数属性不再有效,并将从将来的版本中删除。

已更改容量模型的内部模型架构

  • vidi_training.h vidi_training_tool_train2 C++ 函数中,已更改 training_artifact_key 参数的选项。

  • ViDi2.Training.IToolParametersHighDetail.NetworkModel C# 函数中,选项已更改。

更改了 count_epochspatience training_parameters 的机制和有效值范围

  • vidi_training.h vidi_training_set_parametervidi_training.h vidi_training_tool_set_parameter C++ 函数中:

    • training_parameters/count_epochs 参数的有效值范围已更改为 [50, 100000]。

    • training_parameters/patience 参数的有效值范围已更改为 [0, 100]。

  • ViDi2.Training.IToolParametersHighDetail.CountEpochsViDi2.Training.IToolParametersHighDetail.Patience C# 函数已更改。

有关新机制的更多信息,请参阅VisionPro Deep Learning软件帮助

自动调整大小模式引入参数

删除 vidi_runtime_tool_convert_trt 函数的 width, height 参数的默认参数

  • 与旧版相比,vidi_runtime.h vidi_runtime_tool_convert_trt 函数已更改,如下所示:

    • VisionPro Deep Learning 3.2.0:

      • VIDI_INT width = 0

      • VIDI_INT height=0

    • VisionPro Deep Learning 3.3.0:

      • VIDI_INT width,

      • VIDI_INT height,

  • ViDi2.Runtime.ITool.OptimizeTensorRT C# 函数已更改,如下所示:

    • VisionPro Deep Learning 3.2.0:
      • int width = 0, int height = 0
    • VisionPro Deep Learning 3.3.0:

      • int width, int height,

这些参数是优化的 TensorRT 模型关闭 特征集合的特定空间排列(仅限蓝色定位和蓝色读取工具。)在后处理步骤中,蓝色定位和蓝色读取工具可以将在图像中检测的所有特征与该工具定义的模型相拟合。然后返回模型的整体位姿和标识。的目标尺寸。如果要处理的图像大小相同,则使用完全相同的图像宽度和高度。但是,如果图像大小不同,则请根据要处理的图像中最大的宽度和高度来设置各自的宽度和高度。

VisionPro Deep Learning 3.2

GPU 时钟稳定器

首先,您可以尝试调整 GPU 时钟设置以防止降低 GPU 时钟。请在“Nvidia 控制面板”>“管理 3D”设置中将“电源管理模式”更改为“首选最高性能”。不过,如果 GPU 时钟仍无法维护,请考虑与名为“GPU 时钟稳定器”的新功能一起使用。

在部署环境中维护稳定的 GPU 时钟的功能在多 GPU 场景或时钟不稳定导致处理速度降低或达到峰值的情况下非常有用。

有关详细信息,请参阅下面的示例代码。

注意
  • 默认情况下,此功能最初处于禁用状态。您可以通过 API 控制其激活或停用状态。
  • 此功能应在计算设备初始化之后使用。在初始化之前尝试使用此功能会造成 C API 返回 VIDI_SUCCESS 之外的值,同时 .NET API 会触发异常。

复制
C++ Example of GPU Clock Stabilizer
...
                /** @brief disable stabilize feature  */
                #define VIDI_STABILIZE_OFF 0
 
                /** @brief enable stabilize feature on GPUs  */
                #define VIDI_STABILIZE_GPU 1
 
                /** @brief stabilize the compute devices
                *   @param mode mode of operation
                *   @return 0 if passed, otherwise an error_code that can be used with vidi_get_error_message()
                *
                *   @see VIDI_STABILIZE_GPU, VIDI_STABILIZE_OFF
                *   This method must be called after the compute devices have been initialized.
                */
                VIDI_DLLEXPORT  VIDI_UINT vidi_stabilize_compute_device(VIDI_INT mode); 
 
                ///////////////////////////////////////////////////////
                // example
                ///////////////////////////////////////////////////////
 
                // Turns on.
                vidi_stabilize_compute_device(VIDI_STABILIZE_GPU);
 
                // Turns off
                vidi_stabilize_compute_device(VIDI_STABILIZE_OFF);
            ...
复制
C# Example of GPU Clock Stabilizer
...
                /// <summary>
                    /// Offers the possibility to stabilize the compute devices when the control is created, without unloading the vidi dll
                    /// example: mode =  "StabilizeMode.Off"
                    ///          mode =  "StabilizeMode.GPU"
                    /// This can only be called after compute devices initialized.
                /// </summary>
                void StabilizeComputeDevices(Enum mode);
 
 
                ///////////////////////////////////////////////////////
                // example
                ///////////////////////////////////////////////////////
 
                // Turns on
                control.StabilizeComputeDevices(StabilizeMode.GPU);
 
                // Turns off
                control.StabilizeComputeDevices(StabilizeMode.Off);
            ...

vidi_initialize2() 已弃用

vidi_initialize2() 函数已弃用。
从版本 VisionPro Deep Learning 3.2.0 开始,您可以同时加载和使用训练 API 和运行时 API。尽管 vidi_initialize2() API 仍存在,但它不执行预期的操作。

复制
Deprecated vidi_initialize2()
VIDI_DLLEXPORT  VIDI_UINT vidi_initialize2(VIDI_INT compute_mode, VIDI_STRING compute_devices, VIDI_INT cuda_load_mode);

VisionPro Deep Learning 3.0

VisionPro Deep Learning 3.0 中引入的新功能中,由于 API 增强了运行时功能,部分功能只能通过 API 提供。

用于运行时 API 的分类批处理

绿色分类标准现在可以通过批处理功能一次处理多个视图。使用下列运行时 API 可以通过 API 加快绿色分类标准处理速度。

使用分类批处理 API 的步骤汇总如下。

  1. 修复批次大小并准备要处理的图像。最大批次大小取决于当前可用的 GPU 内存。

  2. 创建样本。

  3. 将准备好的图像添加到样本中。

  4. 运行批处理。

  5. 检查处理结果。

有关利用批次处理 API 的更多详细信息,请参阅下面的示例代码。

注意如果您选择的批次大小大于在步骤 1 中根据当前 GPU 的可用内存计算的最大批次大小,批处理将无法开始。
复制
C++ Example of Batch Processing API for Runtime (Green High Detail)
...
// The maximum batch size depends on the available GPU memory size.
// let's suppose the available maximum batch size is 12.
constexpr int batch_size = 12;
 
// you need to set "runtime_parameters/batch_size" as the batch size you chose above.
// "workspace": the name of your workspace
// "default": the name of the stream in your workspace
// "Classify": the name of the Green High Detail tool in your stream.
string batch_size_str = std::to_string(batch_size);
vidi_runtime_tool_set_parameter("workspace", "default", "Classify", "runtime_parameters/batch_size", batch_size_str.c_str());
...
// you also need to prepare the same number of the images as the batch size
vector<VIDI_IMAGE> images(batch_size);
for (int i = 0; i < batch_size; i++)
{
    ...
    status = vidi_load_image(image_path.c_str(), &images[i]);
    ...
}
...
// create a sample for batch processing. Note that a sample is the basic unit of processing task.
// "my_sample": the name of the sample you create.
status = vidi_runtime_create_batched_sample("workspace", "default", "my_sample");
...
// add the prepared images to the sample
for (int i = 0; i < batch_size; i++)
{
    ...
    status = vidi_runtime_batched_sample_add_image("workspace", "default", "my_sample", &images[i]);
    ...
}
...
// execute batch processing
status = vidi_runtime_batched_sample_process("workspace", "default", "Classify", "my_sample", "");
...
// get result of batch processing
status = vidi_runtime_get_batched_sample("workspace", "default", "my_sample", &result_buffer);
...
复制
C# Example of Batch Processing API for Runtime (Green High Detail)
...
// The maximum batch size depends on the available GPU memory size.
// let's suppose the available maximum batch size is 12.
int batch_size = 12;
...
// you also need to prepare the same number of the images as the batch size
// the paths list should contain the paths of images
List<IImage> imgs = new List<IImage>();
for (int i = 0; i < batch_size; ++i)
    imgs.Add(new LibraryImage(paths[i]));

// create a sample for batch processing. Note that a sample is the basic unit of processing task.
// "Classify": the name of the Green High Detail tool in your stream.
using (IBatchedSample sample = stream.CreateBatchedSample())
{
    // add images to sample
    for (int i = 0; i < batch_size; ++i)
        sample.AddImage(imgs[i]);

    ITool greenTool = stream.Tools["Classify"];

      // set batch size parameter 
      var param = greenTool.ParametersBase as ViDi2.Runtime.IGreenHighDetailParameters;
    param.BatchSize = batch_size;
    
    // run processing
    sample.Process(greenTool);
    
    // get processing result of batch
    for (int i = 0; i < batch_size; ++i)
    {
        var tags = sample.Tags(greenTool, i);
        foreach (var tag in tags)
            Console.WriteLine($"tag: name={tag.Key}, score={tag.Value}");
    }
}
注意批处理不应在工具链中使用。如果您要在工具链中使用批处理,请为每个工具创建运行时工作区并将其链在一起。

运行时支持 API NVIDIA TensorRT

NVIDIA TensorRT 是 NVIDIA SDK,它加快了深度学习应用程序的推断速度。它通过 NVIDIA GPU 模型优化了深度神经网络的推断速度。从 VisionPro Deep Learning 3.0 开始,运行时 API 支持 TensorRT 加快在运行时的处理速度。要使用运行时 API 的 TensorRT,请执行以下步骤。仅针对红色分析标准绿色分类标准运行时环境支持运行时 API 的 TensorRT。

  1. 在训练环境中,创建工作区、流和标准工具。训练工具,让其可以随时部署在运行时环境中。训练环境可以是 VisionPro Deep Learning GUI 或 API。您可以创建工作区、流和高细节工具,并在 GUI 中训练工具。

  2. 导出包含训练标准工具的运行时工作区。您也可以在 GUI 中创建运行时工作区(“工作区”>“导出运行时工作区”)。

  3. 在前端设备上部署运行时工作区及其标准工具。

  4. 在运行时工作区中使用 TensorRT 运行 TensorRT 优化 API 来优化标准工具,从而节省运行时工作区。

    注意如果图像大小相同,则使用完全相同的图像宽度和高度。但是,如果图像大小不同,则请根据要处理的图像中最大的宽度和高度来设置各自的宽度和高度。
  5. 优化完成时间通常不到 10 分钟。第一次优化运行后,该工具的神经网络将针对您使用的特定 NVIDIA GPU 模型进行优化。从此时开始,您便可以更快的速度处理尽可能多的图像。

    复制

    C++ Example of TensorRT Optimization API for Runtime (Red High Detail and Green High Detail)

    ...
    // open the given workspace.
    // "workspace": the name of your runtime workspace
    //"..\\..\\resources\\runtime\\Green High-detail Tool.vrws": the path to the runtime workspace file
    status = vidi_runtime_open_workspace_from_file("workspace", "..\\..\\resources\\runtime\\Green High-detail Tool.vrws");
    ...

    // optimize the High-detail tool
    // "default": the name of the stream in your workspace
    // "Classify": the name of the Green High Detail tool in your stream.
    clog << "Start optimization. It will take a few minutes." << endl;
    status = vidi_runtime_tool_convert_trt("workspace", "default", "Classify", 0);
    ...

    // save runtime workspace with the optimized tool
    string save_path = "..\\..\\resources\\runtime\\Green High-detail Tool optimized.vrws";   
    status = vidi_runtime_save_workspace("workspace", save_path.c_str());
    clog << "The workspace with the optimized tool is saved at " << save_path.c_str() << endl;
    ...
    复制
    C# Example of TensorRT Optimization API for Runtime (Red High Detail and Green High Detail)
    ...
    // Open a runtime workspace from file
    // the path to this file relative to the example root folder
    // and assumes the resource archive was extracted there.               
    // "workspace": the name of your runtime workspace
    ViDi2.Runtime.IWorkspace workspace = control.Workspaces.Add("workspace", "..\\..\\..\\..\\resources\\runtime\\Green High-detail Tool.vrws");
     
    // Store a reference to the stream 'default'
    IStream stream = workspace.Streams["default"];
     
    // "Classify": the name of the Green High Detail tool in your stream.
    var greenTool = stream.Tools["Classify"] as ViDi2.Runtime.IGreenTool;
     
    // Optimizes the High-Detail tool with TensorRT. It takes some time to optimize the tool.
    greenTool.OptimizeTensorRT(0);
     
    // Save runtime workspace with the optimized tool.
    // You can use this workspace to process with the optimized tool.
    string savePath = "..\\..\\..\\..\\resource\\runtime\\Green High-detail Tool Optimized.vrws";
    workspace.Save(savePath);
    Console.Write($"The workspace with the optimized tool is saved at {savePath}."); 
    ...

    如果您要将 与 TensorRT 优化的处理一起使用,则需要在调用优化功能前设置批次大小。

    复制
    C++ Example of Setting Batch Size Before Calling TensorRT Optimization (Green High Detail)
    // Optimize with batchSize=16
    // The 5th(width) and 6th(height) parameter of vidi_runtime_tool_convert_trt() are for target width and height for optimization
    // If width=0 or height=0 is provided, the trained size is used. So we just recommend use width=0, height=0 in normal case.
    int gpu_index = 0;
    int batch_size = 16;
    vidi_runtime_tool_convert_trt("workspace", "default", "Analyze", gpu_index, 0, 0, batch_size);
    复制
    C# Example of Setting Batch Size Before Calling TensorRT Optimization (Green High Detail)
    // Optimize with batchSize=16
    // The second(width) and third(height) parameter of OptimizeTensorRT() are for target width and height for optimization
    // If width=0 or height=0 is provided, the trained size is used. So we just recommend use width=0, height=0 in normal case.
    int gpuIndex = 0;
    int batchSize = 16;
    greenTool.OptimizeTensorRT(gpuIndex, 0, 0, batchSize);

    C++ 完整示例代码目录:

    C:/ProgramData/Cognex/VisionPro Deep Learning/3.0/Examples/c++/Example.Runtime.OptimizeHDTool

    C:\ProgramData\Cognex\VisionPro Deep Learning\3.0\Examples\c++\Example.Runtime.HDGreen.Batched

    C# 完整示例代码的目录:

    C:/ProgramData/Cognex/VisionPro Deep Learning/3.0/Examples/c#/Example.Runtime.OptimizeHDTool.Console

    C:\ProgramData\Cognex\VisionPro Deep Learning\3.0\Examples\c#\Example.Runtime.HDGreen.Batched.Console

    将您的运行时工作区加载到您的应用中,并将其部署到设备上,以便使用 TensorRT 优化工具处理图像。为此,您需要在处理前设置参数。

    复制
    C++ Example of Setting Parameter to Use TensorRT Optimized-model for Processing (Red High Detail and Green High Detail)
    // If you want to process with optimized tool, you have to set ProcessTensorRT to true.
    // Setting this option to true will trigger TensorRT processing.
    status = vidi_runtime_tool_set_parameter("workspace", "default", "Analyze", "runtime_parameters/process_with_trt", "true");
    ...
    status = vidi_runtime_sample_process("workspace", "default", "Analyze", "my_sample", "");
    复制
    C# Example of Setting Parameter to Use TensorRT Optimized-model for Processing (Red High Detail and Green High Detail)
    // If you want to process with optimized tool, you have to set ProcessTensorRT to true.
    // Setting this option to true will trigger TensorRT processing.
    var hdParam = hdTool.ParametersBase as ViDi2.Runtime.IToolParametersHighDetail;
    hdParam.ProcessTensorRT = true;
    ...
    sample.Process(hdTool);

    请参阅下面的示例代码以使用运行时工作区处理图像。

    C# 示例代码的目录:

    • C:/ProgramData/Cognex/VisionPro Deep Learning/3.0/Examples/c#/Example.Runtime.HDGreen.Console

    • C:/ProgramData/Cognex/VisionPro Deep Learning/3.0/Examples/c#/Example.Runtime.HDRed.Console

    C++ 示例代码的目录:

    • C:/ProgramData/Cognex/VisionPro Deep Learning/3.0/Examples/c++/Example.Runtime.HDGreen

    • C:/ProgramData/Cognex/VisionPro Deep Learning/3.0/Examples/c++/Example.Runtime.HDRed

    注意TensorRT 优化 API(vidi_runtime_tool_convert_trt,.OptimizeTensorRT)应在 NVIDIA GPU 型号变更后再次调用,因为只有 NVIDIA GPU 型号才能执行优化。如果您在设备中更改了 NVIDIA GPU 型号,请重复步骤 4 和 5。

VisionPro Deep Learning 2.1.1

VisionPro Deep Learning 2.1.1 中,仅在 API 中为蓝色定位和蓝色读取添加了新处理参数 max_scan_iterations。该参数限制了处理过程中图像扫描的最大迭代次数关闭 通过反复向网络提供采样图像数据、处理数据,将结果与预期的真值进行比较,然后调整网络权重并再次尝试训练深度学习工具。迭代次数计数是通过网络处理每个输入样本的次数。,为该参数提供固定次数可加快处理速度。

注意max_scan_iterations 的值设置得太低时,检测到的特征关闭 特征是图像上可进行视觉辨识的区域。特征通常代表对应用相关的内容(缺陷、对象、对象的特定部分)。或字符特征数可能比预期的少。该参数的适当值取决于图像。

您可以通过下列参数获取此参数的值:

  • vidi_runtime_get_parameter

  • vidi_runtime_tool_get_parameter

您可以通过下列参数更改此参数的值:

  • vidi_runtime_set_parameter

  • vidi_runtime_tool_set_parameter

max_scan_iterations 的参数路径是:

  • processing/blue/max_scan_iterations

示例

此主题介绍 C 和 .NET API 的 max_scan_iterations 参数的代码示例

符号 定义
工作区 工作区的名称。
工作区中流的名称。
工具 流中工具的名称。
40 参数的值。
复制

C API

VIDI_UINT status = vidi_runtime_tool_set_parameter("WORKSPACE", "STREAM", "TOOL", "processing/blue/max_scan_iterations", "40");
复制

.NET API

libraryAccess.SetToolParameter("WORKSPACE", "STREAM", "TOOL", "processing/blue/max_scan_iterations", "40"); // libraryAccess is ILibraryAccess

VisionPro Deep Learning 2.1

由于在 VisionPro Deep Learning4.0 中添加了高细节快速模式,API 也发生了一些变化。

绿色分类高细节快速训练 - C API

复制

Green High Detail Quick Training with C API

// Green high-detail-quick mode
...
param_ss << "workspaces/" << workspace_name << "/streams/" << stream_name << "/tools/" << tool_name << "/tool_type";
status = vidi_training_set_parameter(param_ss.str().c_str(), "green_quick");
...

要训练绿色分类高细节快速,应将 vidi_training_set_parameter 的参数路径设置为“green_quick”。

参数路径的示例:

  • workspaces/WORKSPACE_NAME/streams/STREAM_NAME/tools/TOOL_NAME/tool_type

符号 定义
WORKSPACE_NAME

工作区的名称。

STREAM_NAME

工作区中流的名称。

TOOL_NAME

流中工具的名称。

要为绿色分类高细节快速配置工具参数,还应设置参数路径。例如,如果要更改训练参数中的迭代次数计数,请将参数路径设置为:

  • workspaces/WORKSPACE_NAME/streams/STREAM_NAME/tools/TOOL_NAME/training_parameters/count_epochs

符号 定义
WORKSPACE_NAME

工作区的名称。

STREAM_NAME

工作区中流的名称。

TOOL_NAME

流中工具的名称。

有关训练 C API 代码的更详细示例,请参阅“C:\ProgramData\Cognex\VisionPro Deep Learning\2.1\Examples\c++\Example.Training.HDGreen\example_training_hdgreen.cpp”。

绿色分类高细节快速训练 - .NET API

复制

Green High Detail Quick Training with .NET API

...
// Green high-detail-quick mode
hdGreenTool.Database.Tool.Type = ToolType.GreenQuickHighDetail;
...

要训练绿色分类高细节快速,应将 ViDi2.Training.ITool.Type 设置为 ToolType.GreenQuickHighDetail

要为绿色分类高细节快速配置工具参数,应设置 ViDi2.Training.IGreenHighDetailParameters。例如,应为 IGreenHighDetailParameters 设置 CountEpochs 的值。

有关训练 .NET API 代码的更详细示例,请参阅“C:\ProgramData\Cognex\VisionPro Deep Learning\2.1\Examples\c#\Example.Training.HDGrProgrameen.Console\.cs”

绿色分类高细节快速处理 - C API

使用 API 处理绿色分类高细节快速的方式与绿色分类聚焦和绿色分类高细节相同。有关详细信息,请参阅“C:\ProgramData\Cognex\VisionPro Deep Learning\2.1\Examples\c++\Example.Runtime.HDGreen\example_runtime_hdgreen.cpp”

绿色分类高细节快速处理 - .NET API

使用 API 处理绿色分类高细节快速的方式与绿色分类聚焦和绿色分类高细节相同。有关详细信息,请参阅“C:\ProgramData\Cognex\VisionPro Deep Learning\2.1\Examples\c#\Example.Runtime.HDGreen.Console\Program.cs”

红色分析高细节快速训练 - C API

复制

Red High Detail Quick Training with C API

...
// Red high-detail quick mode
param_ss << "workspaces/" << workspace_name << "/streams/" << stream_name << "/tools/" << tool_name << "/tool_type";
status = vidi_training_set_parameter(param_ss.str().c_str(), "red_quick");
...

要训练红色分析高细节快速,应将 vidi_training_set_parameter 的参数路径设置为“red_quick”。

参数路径的示例:

  • workspaces/WORKSPACE_NAME/streams/STREAM_NAME/tools/TOOL_NAME/tool_type

符号 定义
WORKSPACE_NAME

工作区的名称。

STREAM_NAME

工作区中流的名称。

TOOL_NAME

流中工具的名称。

要为红色分析高细节快速配置工具参数,还应设置参数路径。例如,如果要更改训练参数中的迭代次数计数,请将参数路径设置为:

  • workspaces/WORKSPACE_NAME/streams/STREAM_NAME/tools/TOOL_NAME/training_parameters/count_epochs

符号 定义
WORKSPACE_NAME

工作区的名称。

STREAM_NAME

工作区中流的名称。

TOOL_NAME

流中工具的名称。

有关训练 C API 代码的更详细示例,请参阅“C:\ProgramData\Cognex\VisionPro Deep Learning\2.1\Examples\c++\Example.Training.HDRed\example_training_hdred.cpp”

红色分析高细节快速训练 - .NET API

复制

Red High Detail Quick Training with .NET API

...
// Red high-detail quick mode
hdRedTool.Database.Tool.Type = ToolType.RedQuickHighDetail;
...

要训练红色分析高细节快速,应将 ViDi2.Training.ITool.Type 设置为 ToolType.RedQuickHighDetail

要为红色分析高细节快速配置工具参数,应设置 ViDi2.Training.IRedHighDetailParameters。例如,应为 IRedHighDetailParameters 设置 CountEpochs 的值。

有关训练 .NET API 代码的更详细示例,请参阅“C:\ProgramData\Cognex\VisionPro Deep Learning\2.1\Examples\c#\Example.Training.HDRed.Console\Program.cs”

红色分析高细节快速处理 - C API

使用 API 处理红色分析高细节快速的方式与红色分析聚焦监督和红色分析高细节相同。有关详细信息,请参阅“C:\ProgramData\Cognex\VisionPro Deep Learning\2.1\Examples\c++\Example.Runtime.Red\example_runtime_red.cpp”

红色分析高细节快速处理 - .NET API

使用 API 处理红色分析高细节快速的方式与红色分析聚焦监督和红色分析高细节相同。有关详细信息,请参阅“C:\ProgramData\Cognex\VisionPro Deep Learning\2.1\Examples\c#\Example.Runtime.HDRed.Console\Program.cs”