解析工具
概述
解析实用程序是一组帮助生成解析规范的函数tf parse_example美元
用于估计器。如果用户保存数据tf美元的例子
格式,他们需要调用tf parse_example美元
这些实用函数有两个主要的帮助:
用户需要将解析规范与标签和权重(如果有的话)结合起来,因为它们都是从相同的地方解析出来的
tf美元的例子
实例。实用程序函数结合了这些规范。这样的估计器很难映射期望的标签
dnn_classifier
到相应的tf parse_example美元
实用函数通过从用户那里获取相关信息(key, dtype)来对其进行编码。
解析规范的示例输出
parsing_spec < -classifier_parse_example_spec(feature_columns =column_numeric(“一个”),label_key =“b”,weight_column =“c”)
对于上面的例子,classifier_parse_example_spec
将返回以下内容:
expected_spec < -列表(一个=特遣部队$python$运维$parsing_ops$FixedLenFeature(网状::元组(1升),dtype =特遣部队$float32),c =特遣部队$python$运维$parsing_ops$FixedLenFeature(网状::元组(1升),dtype =特遣部队$float32),b =特遣部队$python$运维$parsing_ops$FixedLenFeature(网状::元组(1升),dtype =特遣部队$int64))#这应该与我们使用' classifier_parse_example_spec '构造的相同testthat::expect_equal(parsing_spec expected_spec)
分类器的示例用法
首先,定义特征转换并初始化分类器,如下所示:
fcs < -feature_columns(…)模型< -dnn_classifier(n_classes =1000,feature_columns =fcs,weight_column =“example-weight”,label_vocabulary =c(“照片”,“保持”、……)hidden_units =c(256,64,16))
接下来,创建解析配置tf parse_example美元
使用classifier_parse_example_spec
还有专题专栏fcs
我们刚刚定义了:
parsing_spec < -classifier_parse_example_spec(feature_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_features(file_pattern =train_files,batch_size =batch_size,特点=parsing_spec,读者=特遣部队$RecordIOReader)标签< -特性[[“公司”]]返回(列表(功能、标签)}
最后,利用分析得到的训练输入函数对模型进行训练classifier_parse_example_spec
: