Halcon 深度学习 分类预处理

文章目录

  • 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.mfbz.cn/a/875682.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Java wrapperr打包springboot项目到linux和Windows

Java wrapper打包springboot项目到linux和Windows 1 Java wrapper 说明2 linux的安装步骤2.1 解压 创建目录2.2 复制文件2.3 配置文件2.4 启动 3 windows3.1 配置文件3.2 复制文件3.3 启动 1 Java wrapper 说明 前提: 一定要有Java环境(我使用的是jdk1.8…

C和指针:指针

内存和地址 程序视角看内存是一个大的字节数组,每个字节包含8个位,可以存储无符号值0至255,或有符号值-128至127。 多个字节可以合成一个字,许多机器以字为单位存储整数,每个字一般由2个或4个字节组成。 由于它们包含了更多的位&…

油耳用什么掏耳朵比较好?可视挖耳勺推荐平价

掏耳朵是一个轻松又舒服的感觉,很多人就会用棉签和普通耳勺越掏越进,在盲掏的过程中容易弄伤耳膜。所以我们在掏耳时要选好工具。市面上的智能可视挖耳勺,顶端带有摄像头,可以通过清楚的观察到耳道中的情况。但现在市面上关于可视…

在Linux中从视频流截取图片帧(ffmpeg )

Linux依赖说明: 说明: 使用到的 依赖包 1. ffmpegsudo apt update sudo apt-get install ffmpeg2. imagemagick (选装) (检测图像边缘信息推断清晰度,如果是简单截取但个图像帧>用不到<)sudo apt-get install imagemagick备注: 指令及相关参数说明核心指令: (作用: 执…

VSCode好用的插件推荐

1. Chinese 将vscode翻译成简体中文 2. ESLint 自动检查规范 3. Prettier - Code formatter 可以自动调整代码的缩进、换行和空格&#xff0c;确保代码风格统一。通过配置&#xff0c;Prettier可以在保存文件时自动格式化代码 https://juejin.cn/post/74025724757198274…

从 Postgres 到 ClickHouse:数据建模指南

本文字数&#xff1a;7149&#xff1b;估计阅读时间&#xff1a;18 分钟 作者&#xff1a;Sai Srirampur 本文在公众号【ClickHouseInc】首发 上个月&#xff0c;我们收购了专注于 Postgres CDC 的 PeerDB。PeerDB 使得数据从 Postgres 复制到 ClickHouse 变得既快速又简单。Pe…

Docker日志管理之Filebeat+ELK日志管理

所需安装包及镜像 安装步骤 把所需镜像导入到Docker容器 打开/etc/sysctl.conf配置文件&#xff0c;添加参数 打开资源限制配置文件&#xff0c;添加参数 创建一个网络 在根目录下创建一个项目目录 创建Elasticsearch子目录 在项目目录下创建Elasticsearch子目录 将安装Elast…

微生物分类检测系统源码分享

微生物分类检测检测系统源码分享 [一条龙教学YOLOV8标注好的数据集一键训练_70全套改进创新点发刊_Web前端展示] 1.研究背景与意义 项目参考AAAI Association for the Advancement of Artificial Intelligence 项目来源AACV Association for the Advancement of Computer V…

突发!OpenAI发布最强模型o1:博士物理92.8分,IOI金牌水平

梦晨 衡宇 发自 凹非寺量子位 | 公众号 QbitAI 参考ChatGPT&#xff1a;点击使用 来了来了&#xff01;刚刚&#xff0c;OpenAI新模型无预警上新&#xff1a; o1系列&#xff0c;可以进行通用复杂推理&#xff0c;每次回答要花费更长时间思考。 在解决博士水平的物理问题时&a…

Notepad++插件:TextFX 去除重复行

目录 一、下载插件 TextFX Characters 二、去重实操 2.1 选中需要去重的文本 2.2 操作插件 2.3 结果展示 2.3.1 点击 Sort lines case sensitive (at column) 2.3.2 点击 Sort lines case insensitive (at column) 一、下载插件 TextFX Characters 点【插件】-【插件管理…

【OpenAPI】Spring3 集成 OpenAPI 生成接口文档

Spring3 集成 OpenAPI 生成接口文档 1. 依赖 Spring 版本&#xff1a;3.0.5 Java 版本&#xff1a;jdk21 OpenAPI 依赖&#xff1a; <!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui --> <dependency><groupI…

如何通过 PhantomJS 模拟用户行为抓取动态网页内容

引言 随着网页技术的不断进步&#xff0c;JavaScript 动态加载内容已成为网站设计的新常态&#xff0c;这对传统的静态网页抓取方法提出了挑战。为了应对这一挑战&#xff0c;PhantomJS 作为一个无头浏览器&#xff0c;能够模拟用户行为并执行 JavaScript&#xff0c;成为了获…

GeoPandas在地理空间数据分析中的应用

GeoPandas是一个开源的Python库&#xff0c;专门用于处理和分析地理空间数据。它建立在Pandas库的基础上&#xff0c;扩展了Pandas的数据类型&#xff0c;使得用户能够在Python中方便地进行GIS操作。GeoPandas的核心数据结构是GeoDataFrame&#xff0c;它是Pandas的DataFrame的…

uniapp小程序,使用腾讯地图获取定位

本篇文章分享一下在实际开发小程序时遇到的需要获取用户当前位置的问题&#xff0c;在小程序开发过程中经常使用到获取定位功能。uniapp官方也提供了相应的API供我们使用。 官网地址&#xff1a;uni.getLocation(OBJECT)) 官网获取位置的详细介绍这里就不再讲述了&#xff0c;大…

红光一字激光器在工业中的性能指标怎样

红光一字激光器作为现代工业中不可或缺的重要设备&#xff0c;以其独特的性能和广泛的应用场景&#xff0c;成为众多行业的首选工具。本文就跟大家详细探讨红光一字激光器在工业中的性能指标&#xff0c;以及这些指标如何影响其在实际应用中的表现。 光束质量 红光一字激光器以…

【痛点解决】跨网跨区域的文件传输摆渡解决办法指南

跨网跨区域的文件传输摆渡&#xff0c;顾名思义就是需要跨越不同网络、不同地区&#xff0c;或者是不同安全域的文件传输&#xff0c;一般有这样传输需求的机构&#xff0c;在组织架构、网络结构&#xff0c;或者传输需求上&#xff0c;都会比较复杂。 跨网跨区域文件传输是什…

51单片机快速入门之定时器和计数器

51单片机快速入门之定时器 断开外部输入 晶振振荡 假设为 12MHz 12分频之后,为1MHz 当其从0-65536 时,需要65536μs 微秒 也就是65.536ms 毫秒 溢出(值>65536 时)>中断>执行中断操作 假设需要1ms后产生溢出,则需要设置初始值为64536 此时定时器会从 64536 开始计…

掌握 JavaScript ES6+:现代编程技巧与模块化实践

掌握 JavaScript ES6&#xff1a;现代编程技巧与模块化实践 一 . 变量声明 let二 . 声明常量 const三 . 模板字符串四 . 函数的参数默认值五 . 箭头函数六 . 对象初始化七 . 解构7.1 接收 JSON 对象7.2 接收数组 八 . 延展操作符九 . 导入和导出9.1 方式一9.2 方式二 这篇文章我…

Android视频编辑:利用FFmpeg实现高级功能

在移动设备上进行视频编辑的需求日益增长&#xff0c;用户期望能够在智能手机或平板电脑上轻松地编辑视频&#xff0c;以满足社交媒体分享或个人存档的需求。Android平台因其广泛的用户基础和开放的生态系统&#xff0c;成为视频编辑应用的理想选择。FFmpeg&#xff0c;作为一个…

Maven入门学习笔记

一、maven介绍 Maven是一款自动化构建工具&#xff0c;专注服务于JAVA平台的项目构建和依赖管理。在javaEE开发的历史上构建工具的发展也经历了一系列的演化和变迁。 管理jar包 当我们使用SSM之后我们就需要使用非常多的jar包 没有maven找jar包非常的麻烦。 使用maven下载…