Halcon 深度学习 分类预处理

news2024/9/21 23:41:52

文章目录

  • read_dl_dataset_classification 产生一个深度学习数据集算子
  • split_dl_dataset 将样本分为训练、验证和测试子集
  • create_dl_preprocess_param 使用预处理参数创建字典
  • preprocess_dl_dataset 预处理DLDataset中声明的整个数据集
  • write_dict 写入字典文件
  • find_dl_samples 根据模式集检索包含与KeyValue匹配的KeyName的样本索引。
  • tuple_shuffle 随机对元组的元素进行排序
  • read_dl_samples 读取样本
  • dev_display_dl_data 可视化样本的不同图像、注释和推理结果
  • dev_close_window_dict 关闭数据字典
  • 案例 分类药丸

read_dl_dataset_classification 产生一个深度学习数据集算子

read_dl_dataset_classification( : : RawImageFolder, LabelSource : DLDataset)
RawImageFolder (input_control): 字符串数组,表示包含已标记图像的文件夹路径。这些文件夹中的图像应按类别组织,使得可以通过文件夹名或其他方式轻松地识别其类别标签。

LabelSource (input_control): 字符串,指定如何从图像文件夹结构中提取标签信息。默认值为 'last_folder',意味着标签将从图像所在的最后一个文件夹名中获取。例如,如果图像位于 /path/to/class1/image1.jpg 和 /path/to/class2/image2.jpg,那么 class1 和 class2 将作为标签。

DLDataset (output_control): 返回的数据集字典。这个字典包含了从指定文件夹中读取的所有图像及其对应的标签信息。这个数据集可以用于后续的数据处理操作,比如数据增强、分割成训练集和验证集等

split_dl_dataset 将样本分为训练、验证和测试子集

split_dl_dataset( : : DLDataset, TrainingPercent, ValidationPercent, GenParam : )

DLDataset (input_control): 输入的数据集字典,该字典包含了关于数据集的信息。这个字典通常包含了所有样本的图像及其对应的标签。
TrainingPercent (input_control): 整数或实数类型,表示分配给训练数据集的样本百分比。默认值为 60%,即 60% 的数据将用于训练。该值的有效范围为 0100ValidationPercent (input_control): 整数或实数类型,表示分配给验证数据集的样本百分比。默认值为 20%,即 20% 的数据将用于验证。该值的有效范围为 0100GenParam (input_control): 任何类型,这里通常是一个字典,用于指定非默认的数据集划分参数。默认情况下为空字典 [],表示使用默认的划分策略。

create_dl_preprocess_param 使用预处理参数创建字典

create_dl_preprocess_param( : : DLModelType, ImageWidth, ImageHeight, ImageNumChannels, ImageRangeMin, ImageRangeMax, NormalizationType, DomainHandling, IgnoreClassIDs, SetBackgroundID, ClassIDsBackground, GenParam : DLPreprocessParam)

DLModelType (input_control): 字符串类型,用于指定预处理过程中针对的深度学习模型类型。默认值为 'segmentation'。建议值包括 'classification''multi_label_classification''detection''segmentation''3d_gripping_point_detection''ocr_recognition''ocr_detection'ImageWidth (input_control): 整数类型,表示图像被重新缩放后的宽度。有效值区间为 1 及以上。
ImageHeight (input_control): 整数类型,表示图像被重新缩放后的高度。有效值区间为 1 及以上。
ImageNumChannels (input_control): 整数类型,表示图像被重新缩放后的通道数。有效值区间为 1 及以上。
ImageRangeMin (input_control): 整数类型,默认值为 -127,表示像素灰度值范围的最小值。
ImageRangeMax (input_control): 整数类型,默认值为 128,表示像素灰度值范围的最大值。
NormalizationType (input_control): 字符串类型,用于指定预处理过程中的归一化类型。默认值为 'none'。建议值包括 'all_channels''first_channel''constant_values''none'DomainHandling (input_control): 字符串类型,用于指定如何处理域(如果存在)。默认值为 'full_domain'。建议值包括 'full_domain''crop_domain''keep_domain'IgnoreClassIDs (input_control): 整数或整数数组类型,默认值为 [],表示在训练期间应忽略的类别 ID。
SetBackgroundID (input_control): 整数或整数数组类型,默认值为 [],表示背景类别的类别 ID。
ClassIDsBackground (input_control): 整数或整数数组类型,默认值为 [],表示设置为背景类别的类别 ID。
GenParam (input_control): 任意类型,默认值为 [],表示通用参数的字典。
DLPreprocessParam (output_control): 输出的预处理参数字典。

preprocess_dl_dataset 预处理DLDataset中声明的整个数据集

preprocess_dl_dataset( : : DLDataset, DataDirectory, DLPreprocessParam, GenParam : DLDatasetFileName)

DLDataset (input_control): 输入的数据集字典,该字典包含了关于数据集的信息,例如图像和标签。这个字典将被预处理。
DataDirectory (input_control): 字符串类型,指定存储处理后数据的目录路径。默认值为 'dl_dataset'DLPreprocessParam (input_control): 字典类型,包含了预处理参数。这些参数用于指导数据预处理过程,例如图像的尺寸调整、归一化等。
GenParam (input_control): 任意类型,默认值为 [],是一个字典,用于指定一些通用参数。这些参数可以根据具体的应用场景来定义。
DLDatasetFileName (output_control): 字符串类型,表示处理后的数据集字典的文件路径。

write_dict 写入字典文件

write_dict( : : DictHandle, FileName, GenParamName, GenParamValue : )
    DictHandle (input_control): 字典句柄,用于标识要操作的字典。此参数需要一个句柄类型的输入,且必须包含一个元素。
    FileName (input_control): 文件名,指定要保存或读取字典的文件路径。文件扩展名为 .hdict,表明这是一种特定类型的字典文件格式。

    GenParamName (input_control): 泛型参数名称的字符串或字符串数组,用于指定一些可选的泛型参数。默认值为 []。可选值包括 'compact_json''file_type'、'raise_error_if_content_not_serializable' 和 'use_json_arrays'。

    GenParamValue (input_control): 泛型参数值的字符串、整数或浮点数,对应于 GenParamName 中指定的参数。默认值为 []。建议的值包括 'hdict''json''true''false''low_level'

find_dl_samples 根据模式集检索包含与KeyValue匹配的KeyName的样本索引。

find_dl_samples( : : Samples, KeyName, KeyValue, Mode : SampleIndices)
   Samples (input_control): 字典或包含字典的元组数组,表示要遍历的样本集合。每个样本是一个字典。

    KeyName (input_control): 字符串类型,指定要查找的键名。默认值为 'split'KeyValue (input_control): 任何类型(整数、浮点数或字符串),表示在键名 KeyName 下查找的值。默认值为 []。建议值包括 12.2'string'[1, 2.2, 'mixed']Mode (input_control): 字符串类型,定义搜索行为。默认值为 'match'。可选值包括 'match''or''contain'SampleIndices (output_control): 整数数组类型,表示根据设定的模式匹配到的样本索引。

tuple_shuffle 随机对元组的元素进行排序

tuple_shuffle( : : Tuple : Shuffled)
Tuple (input_control): 输入的元组,可以包含任何类型的数据(整数、浮点数、字符串等)。
Shuffled (output_control): 输出控制参数,表示经过处理(例如洗牌)后的元组。

read_dl_samples 读取样本

read_dl_samples( : : DLDataset, SampleIndices : DLSampleBatch)
    DLDataset (input_control): 输入的字典,包含了关于数据集的信息。这个字典通常包含了数据集中的所有样本及其相关信息(如图像、标签等)。

    SampleIndices (input_control): 整数或整数数组类型,表示在字典 DLDataset 中要读取的样本索引。默认值为 []。该值的有效区间为 0 及以上。

    DLSampleBatch (output_control): 输出控制参数,表示从磁盘读取的 DLSample 字典或 DLSample 字典组成的元组。

dev_display_dl_data 可视化样本的不同图像、注释和推理结果

dev_display_dl_data( : : DLSample, DLResult, DLDatasetInfo, KeysForDisplay, GenParam, WindowHandleDict : )


    DLSample (input_control): 输入的样本字典,包含了需要可视化的样本信息。默认值为 []DLResult (input_control): 输入的结果字典,包含了指定样本的预测结果。默认值为 []DLDatasetInfo (input_control): 输入的数据集信息字典或深度学习模型句柄,用于获取 DLResult。默认值为 []。如果为空,则尝试从 DLSample 或 DLResult 推断存在的类别 ID。如果提供了分类或检测模型的 DLResult,则还会从 DLResult 推断类别名称,否则类别名称将显示为 'unknown'KeysForDisplay (input_control): 字符串或字符串数组,指定了请求的可视化类型。建议值包括 'image''classification_ground_truth''classification_result''classification_both''segmentation_weight''segmentation_weight_map''segmentation_confidence''segmentation_confidence_map''bbox_ground_truth''bbox_result''bbox_both''segmentation_image_ground_truth''segmentation_image_result''segmentation_image_both''segmentation_image_diff'GenParam (input_control): 通用参数字典,包含了一些可选的通用参数。默认值为 []WindowHandleDict (input_control): 包含窗口句柄的字典,用于指定可视化的窗口。

dev_close_window_dict 关闭数据字典

dev_close_window_dict( : : WindowHandleDict : )

案例 分类药丸

在这里插入图片描述

预处理 设置文件路径

* 
* This example is part of a series of examples, which summarizes
* the workflow for DL classification. It uses the MVTec pill dataset.
* 
* The four parts are:
* 1. Dataset preprocessing.
* 2. Training of the model.
* 3. Evaluation of the trained model.
* 4. Inference on new images.
* 
* Hint: For a concise version of the workflow please have a look at the example:
* dl_classification_workflow.hdev
* 
* This example contains part 1: 'Dataset preprocessing'.
* 
dev_update_off ()
* 
* In this example, the preprocessing steps are explained in graphics windows,
* before they are executed. Set the following parameter to false in order to
* skip this visualization.
ShowExampleScreens := true
* 预处理
if (ShowExampleScreens)
    * Initial example windows and parameters etc.
    dev_example_init (ShowExampleScreens, ExampleInternals)
    * 
    * Introduction text of example series.
    dev_display_screen_introduction_part_1 (ExampleInternals)
    stop ()
    dev_display_screen_introduction_part_2 (ExampleInternals)
    stop ()
    * 
    * Read the dataset.
    dev_display_screen_read_dataset (ExampleInternals)
    stop ()
    * 
    * Explain splitting the dataset.
    dev_display_screen_split_dataset (ExampleInternals)
    stop ()
    * 
    * Explain how to preprocess the dataset and run the program.
    dev_display_screen_run_program (ExampleInternals)
    stop ()
endif
* 
* *********************************
* **   Set Input/Output paths   ***
* *********************************
* 
* Get the path to the examples.
* 获取系统路径
get_system ('example_dir', PathExample)
* Folder with ground truth classification image data.
* 获取文件路径
RawImageBaseFolder := PathExample + '/images/pill/'
* 
* All example data is written to this folder.
* 写入文件夹数据名称
ExampleDataDir := 'classify_pill_defects_data'
* Dataset directory basename for any outputs written by preprocess_dl_dataset.
* 由preprocess_dl_Dataset编写的任何输出的数据集目录基名。
DataDirectoryBaseName := ExampleDataDir + '/dldataset_pill'
* 
* *************************
* **   Set parameters   ***
* *************************
* 
* LabelSource for reading in the dataset.
LabelSource := 'last_folder'
* 
* Percentages for splitting the dataset.
* 训练集 70% 验证集15%
TrainingPercent := 70
ValidationPercent := 15
* 
* Some models may have limitations regarding the image properties,
* see read_dl_model () for the model of your choice.
* Image dimensions the images are rescaled to during preprocessing.
* 图片的宽高,轨道数量
ImageWidth := 300
ImageHeight := 300
ImageNumChannels := 3
* 
* Further parameters for image preprocessing.
NormalizationType := 'none'
DomainHandling := 'full_domain'
* 
* In order to get a reproducible split we set a random seed.
* This means that re-running the script results in the same split of DLDataset.
* 随机种子
SeedRand := 42
* 
* *****************************************************************************
* **   Read the labeled data and split it into train, validation and test   ***
* *****************************************************************************
* 
* Set the random seed.
* 设置随机种子
set_system ('seed_rand', SeedRand)

产生数据集进行预处理

* 产生深度学习数据集
read_dl_dataset_classification (RawImageBaseFolder, LabelSource, DLDataset)
* Generate the split.
* 产生数据分类
split_dl_dataset (DLDataset, TrainingPercent, ValidationPercent, [])
* 
* 
* *********************************
* **   Preprocess the dataset   ***
* *********************************
* 
* Create the output directory if it does not exist yet.
file_exists (ExampleDataDir, FileExists)
if (not FileExists)
    make_dir (ExampleDataDir)
endif
* 
* Create preprocess parameters.
* 创建预处理数据字典
create_dl_preprocess_param ('classification', ImageWidth, ImageHeight, ImageNumChannels, -127, 128, NormalizationType, DomainHandling, [], [], [], [], DLPreprocessParam)
* 
* Dataset directory for any outputs written by preprocess_dl_dataset.
*preprocess_dl_Dataset编写的任何输出的数据集目录。
DataDirectory := DataDirectoryBaseName + '_' + ImageWidth + 'x' + ImageHeight
* 
* Preprocess the dataset. This might take a few seconds.
* 对数据字典预处理
GenParam := dict{overwrite_files: 'auto'}
preprocess_dl_dataset (DLDataset, DataDirectory, DLPreprocessParam, GenParam, DLDatasetFileName)
* 
* Store preprocess parameters separately in order to use it, e.g., during inference.
* 存储预处理参数
PreprocessParamFileBaseName := DataDirectory + '/dl_preprocess_param.hdict'
write_dict (DLPreprocessParam, PreprocessParamFileBaseName, [], [])
* 
* *******************************************
* **   Preview the preprocessed dataset   ***
* *******************************************
* 显示预处理数据
* Before moving on to training, it is recommended to check the preprocessed dataset.
* 
* Display the DLSamples for 10 randomly selected train images
* 显示
find_dl_samples (DLDataset.samples, 'split', 'train', 'match', SampleIndices)
tuple_shuffle (SampleIndices, ShuffledIndices)
read_dl_samples (DLDataset, ShuffledIndices[0:9], DLSampleBatchDisplay)
* 
WindowHandleDict := dict{}
for Index := 0 to |DLSampleBatchDisplay| - 1 by 1
    * Loop over samples in DLSampleBatchDisplay.
    dev_display_dl_data (DLSampleBatchDisplay[Index], [], DLDataset, 'classification_ground_truth', [], WindowHandleDict)
    Text := 'Press Run (F5) to continue'
    dev_disp_text (Text, 'window', 'bottom', 'right', 'black', [], [])
    stop ()
endfor
* 
* Close windows that have been used for visualization.
dev_close_window_dict (WindowHandleDict)
* 
if (ShowExampleScreens)
    * Hint to the DL classification training process example.
    dev_display_screen_next_example (ExampleInternals)
    stop ()
    * Close example windows.
    dev_close_example_windows (ExampleInternals)
endif

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2134274.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

[网络]TCP/IP五层协议之应用层,传输层(1)

文章目录 一. 应用层二. 传输层端口号传输层的协议UDPTCPTCP报头TCP协议的核心机制 一. 应用层 应用层是和应用程序直接相关, 和程序猿打交道最多的一层 应用层协议, 里面描述的内容, 就是你写的程序, 通过网络具体按照啥样的形式来传输数据 不同的应用程序, 就可以用不同的应…

PHP 使用Spreadsheet写excel缓存导致内存不断增加

这里写自定义目录标题 问题描述问题解决 问题描述 新增了 Spreadsheet 用于写 excle 文件。 从网上查找一些实例后,封装成 createExcelFormData 函数如下: /*** brief 按照指定的键,将 array2(关联数组) 合并到 array1(关…

【C#】VS插件

翻译 目前推荐较多的 可以单词发言,目前还在开发阶段 TranslateIntoChinese - Visual Studio Marketplace 下载量最高的(推荐) Visual-Studio-Translator - Visual Studio Marketplace 支持翻译的版本较多,在 Visual Studio 代码编辑器中通过 Googl…

YOLOV8实现小目标检测

YOLOV8小目标检测 前言:: yolo版出现很多,基本大同小异 但是这些差异让我们考虑在实验中使用哪个版本会比较好! 在对小目标检测的过程中,yolov7相比yolov8性能更加好。 如果我们还是想使用yolov8,也是可以实…

大模型获利「攻略」浮出水面!ToC 蓬勃发展,ToB 蕴含奥秘

前言 自去年引发“百模大战”,到近日开启“行业价格战”,中国大模型行业迈入了新的发展阶段。在近期的智源大会上,众多专家分享了对大模型发展现状的见解。结合 IDC 近期发布的大模型实测报告以及 Scale AI 的“AI 就绪报告”,大…

热榜:24年秋招没有金九银十?地信应届生想就业,如何入场?

秋招的“金九银十”即将结束,你的秋招到哪一步了? 是早已收获满满offer,还是仍然在海投面试中,亦或者根本没开始呢? 2024年的就业环境到底如何?上周,“2024年的就业环境到底如何?”…

LeetCode(04) 最接近的三数之和 【双指针】

题目描述 给你一个长度为 n 的整数数组 nums 和 一个目标值 target。请你从 nums 中选出三个整数,使它们的和与 target 最接近。 返回这三个数的和。 假定每组输入只存在恰好一个解。 解题思路 首先进行数组排序,时间复杂度 O(nlogn);在…

花3000元自学AI大模型后,她薪水涨了20%

“我看到了一个充满无限可能的新世界”,在面试完AI产品经理这一岗位后,陈漫在社交平台上如此描述自己的感受。 AGI大模型浪潮席卷全球,技术革新越是凶猛,人们的失业焦虑便越加强烈。为了应对AI带来的冲击,有些人决定“…

c++—多态【万字文章】

目录 C—多态1.多态的概念2.多态的定义及实现2.1多态的构成条件2.2虚函数的重写2.2.1虚函数重写的两个例外:2.2.1.1协变2.2.1.2析构函数的重写 2.3 c11的override和final2.3.1final2.3.2override 2.4 重载、重写、重定义的对比 3.抽象类3.1抽象类的概念3.2接口继承和…

组件上的v-model(数据传递),props验证,自定义事件,计算属性

一.props验证 在封装组件时对外界传递过来的props数据进行合法性校验&#xff0c;从而防止数据不合法问题。 1.基础类型检查 String,Number,Boolean,Array,Object,Date,Function,Symbol 2.多个可能的类型 3.必须项校验 4.属性默认值 5.自定义验证函数 <template>&…

CAD2020安装方法

文章目录 下载安装包打开压缩包打开文件夹打开CAD2020文件夹双击运行Setup.exe点击安装选择我接受 点击下一步路径默认点击安装等待加载完成安装完成点击立即启动点击OK点击输入序列号点击我同意点击激活输入序列号和 产品钥密点击下一步选择我具有 Autodesk 提供的激活码以管理…

【北京迅为】《STM32MP157开发板使用手册》- 第二十八章Cortex-M4外部中断实验

iTOP-STM32MP157开发板采用ST推出的双核cortex-A7单核cortex-M4异构处理器&#xff0c;既可用Linux、又可以用于STM32单片机开发。开发板采用核心板底板结构&#xff0c;主频650M、1G内存、8G存储&#xff0c;核心板采用工业级板对板连接器&#xff0c;高可靠&#xff0c;牢固耐…

SRT3D: A Sparse Region-Based 3D Object Tracking Approach for the Real World

基于区域的方法在基于模型的单目3D跟踪无纹理物体的复杂场景中变得越来越流行。然而&#xff0c;尽管它们能够实现最先进的结果&#xff0c;大多数方法的计算开销很大&#xff0c;需要大量资源来实时运行。在下文中&#xff0c;我们基于之前的工作&#xff0c;开发了SRT3D&…

一、轻松部署的大模型开发平台dify.ai

一、轻松部署的大模型开发平台dify.ai 今天学习了大模型&#xff0c;顺便介绍的是一个名为dify.ai的神奇平台&#xff0c;它能让你轻松部署和使用大模型&#xff0c;即使你是编程小白也不用担心。 官网&#xff1a;https://dify.ai/zh 什么是大模型&#xff1f; 首先&#…

C++ nullptr 和NULL的区别

个人主页&#xff1a;Jason_from_China-CSDN博客 所属栏目&#xff1a;C系统性学习_Jason_from_China的博客-CSDN博客 概念概述&#xff1a; 在C中&#xff0c;nullptr 和 NULL 都是用来表示空指针&#xff0c;但它们之间有一些重要的区别&#xff1a; nullptr和NULL之间的区分…

ceph简介

ceph存储简要概述&#xff1a; 通过将文件分解成固定大小对象&#xff0c;然后存放于pool中&#xff0c;每个pool中 可包含多个pg&#xff0c;每个pg中又可包含多个osd 通过crush算法 最终数据落盘到osd中去。 一、ceph 删除osd 步骤1 修改osd数据操作权重值 ceph osd crush r…

【贪心算法】贪心算法

贪心算法简介 1.什么是贪心算法2.贪心算法的特点3.学习贪心的方向 点赞&#x1f44d;&#x1f44d;收藏&#x1f31f;&#x1f31f;关注&#x1f496;&#x1f496; 你的支持是对我最大的鼓励&#xff0c;我们一起努力吧!&#x1f603;&#x1f603; 1.什么是贪心算法 与其说是…

C++ | Leetcode C++题解之第401题二进制手表

题目&#xff1a; 题解&#xff1a; class Solution { public:vector<string> readBinaryWatch(int turnedOn) {vector<string> ans;for (int i 0; i < 1024; i) {int h i >> 6, m i & 63; // 用位运算取出高 4 位和低 6 位if (h < 12 &&a…

如何在算家云搭建MindSearch(智能搜索)

一、MindSearch简介 MindSearch是一款由上海人工智能实验室书生浦语团队提出了 MindSearch&#xff08;思索&#xff09;框架&#xff0c;旨在提供高效、精准的信息检索服务&#xff0c;能够在 3 分钟内主动从 300 网页中搜集整理有效信息&#xff0c;总结归纳&#xff0c;解决…

[“1“, “2“, “3“].map(parseInt)结果

parseInt 的用法 parseInt 是 JavaScript 中的一个全局函数&#xff0c;用于将字符串转换为整数。它的基本语法如下&#xff1a; parseInt(string, radix);string&#xff1a;要解析的字符串。radix&#xff08;可选&#xff09;&#xff1a;字符串的基数&#xff0c;可以是 …