使用张量流估计器计算分类精度

问题描述

我正在使用tf.estimator.DNNLinearCombinedClassifier。我有4个类,在tf.feature_column.indicator列中以字符串表示:

target = tf.feature_column.categorical_column_with_vocabulary_list('delay',('1 day','1 week','1 month','2+ months'))
target = tf.feature_column.indicator_column(target)

目标列包含字符串,这些字符串应该由估算器实时进行1热编码。实际上,数据集是tf.data.Dataset。在解析时,解析函数返回特征向量+编码为tf.string的标签。由于目标列已用于构建估算器:

model = DNNLinearCombinedClassifier(
        ...,n_classes=target.categorical_column.num_buckets,label_vocabulary=target.categorical_column.vocabulary_list,...)

估计人员应该在训练和评估过程中意识到1热点。但是,当我添加分类指控作为补充指标时,在训练过程中出现了错误

def ctg_accuracy(labels,predictions):
    ca = tf.keras.metrics.CategoricalAccuracy()
    ca.update_state(labels,predictions['probabilities'])
    return {'ctg_accuracy': ca}

model = add_metrics(model,ctg_accuracy)
...
tensorflow.python.framework.errors_impl.UnimplementedError: Cast string to float is not supported
...

很显然,“标签”仍然是字符串,并且根本没有经过1热编码。在训练/评估过程中,估算器是否会即时进行1-hot运算?如果是,在训练过程中该度量标准计算是否可以访问此向量?

非常感谢你的助手。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)