【发布时间】:2019-09-06 13:42:53
【问题描述】:
我目前正在学习使用 tensorflow,但在入门时遇到了麻烦。 我想使用最新的 API,即估算器和数据集。但是如果我运行下面给出的代码,我会得到一个错误。
在张量流页面https://www.tensorflow.org/api_docs/python/tf/estimator/DNNRegressor 我发现,“该函数应构造并返回以下之一:* tf.data.Dataset 对象:Dataset 对象的输出必须是具有相同的元组(特征、标签)约束如下。”
我认为我的代码会提供该功能,但似乎有问题,我没有想法。
import tensorflow as tf
def input_evaluation_set():
data = [0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]
labels = []
for d in data:
labels.append(1)
return tf.data.Dataset.from_tensor_slices((tf.constant(data), tf.constant(labels)))
point = tf.feature_column.numeric_column('points')
estimator = tf.estimator.DNNRegressor(feature_columns = [point],hidden_units = [100,100,100])
estimator.train(input_fn = input_evaluation_set)
我希望在具有 3 个隐藏层和 100 个神经元的深度神经网络上运行训练课程,以逼近“常数 1”函数; 相反,我得到错误“ValueError:特征应该是'Tensor's的字典。给定类型:类,'tensorflow.python.framework.ops.Tensor'
【问题讨论】:
标签: python tensorflow machine-learning tensorflow-datasets tensorflow-estimator