解析工具

    概述

    解析实用程序是一组帮助生成解析规范的函数tf parse_example美元用于估计器。如果用户保存数据tf美元的例子格式,他们需要调用tf parse_example美元这些实用函数有两个主要的帮助:

    • 用户需要将解析规范与标签和权重(如果有的话)结合起来,因为它们都是从相同的地方解析出来的tf美元的例子实例。实用程序函数结合了这些规范。

    • 这样的估计器很难映射期望的标签dnn_classifier到相应的tf parse_example美元实用函数通过从用户那里获取相关信息(key, dtype)来对其进行编码。

    解析规范的示例输出

    parsing_spec < -classifier_parse_example_specfeature_columns =column_numeric“一个”),label_key =“b”weight_column =“c”

    对于上面的例子,classifier_parse_example_spec将返回以下内容:

    expected_spec < -列表一个=特遣部队python运维parsing_opsFixedLenFeature(网状::元组(1升),dtype =特遣部队float32),c =特遣部队python运维parsing_opsFixedLenFeature(网状::元组(1升),dtype =特遣部队float32),b =特遣部队python运维parsing_opsFixedLenFeature(网状::元组(1升),dtype =特遣部队int64)#这应该与我们使用' classifier_parse_example_spec '构造的相同testthat::expect_equal(parsing_spec expected_spec)

    分类器的示例用法

    首先,定义特征转换并初始化分类器,如下所示:

    fcs < -feature_columns(…)模型< -dnn_classifiern_classes =1000feature_columns =fcs,weight_column =“example-weight”label_vocabulary =c“照片”“保持”、……)hidden_units =c2566416

    接下来,创建解析配置tf parse_example美元使用classifier_parse_example_spec还有专题专栏fcs我们刚刚定义了:

    parsing_spec < -classifier_parse_example_specfeature_columns =fcs,label_key =“公司”label_dtype =特遣部队字符串,weight_column =“example-weight”

    这个标签配置告诉分类器以下信息:

    • 通过键' example-weight '检索权重
    • Label是字符串,可以是以下其中之一c(“照片”,“保持”,…)
    • 标签“photos”的整数id为0,“keep”为1,等等

    然后定义输入函数read_batch_features从文件中读取批量特性tf美元的例子使用解析配置格式化parsing_spec我们定义:

    input_fn_train < -函数() {< -特点特遣部队普通发布版学习read_batch_featuresfile_pattern =train_files,batch_size =batch_size,特点=parsing_spec,读者=特遣部队RecordIOReader)标签< -特性[[“公司”]]返回列表(功能、标签)

    最后,利用分析得到的训练输入函数对模型进行训练classifier_parse_example_spec

    火车(模型中,input_fn =input_fn_train)