【发布时间】:2018-02-13 14:42:49
【问题描述】:
我正在关注关于tensorflow的教程:https://www.tensorflow.org/tutorials/wide
有很多分类特征需要用tf.feature_column.categorical_column_with_vocabulary_list()转换成稀疏矩阵。
但是,我不想使用预定义的 Estimator,
m = tf.estimator.LinearClassifier(
model_dir=model_dir, feature_columns=base_columns + crossed_columns)
我更喜欢使用装扮好的 NN 模型,其中:
estimator = tf.contrib.learn.Estimator(model_fn=model)
estimator.fit(input_fn=input_fn(df, num_epochs=100, shuffle=True), \
steps=100)
所以在model(),会有
def model(features, labels, mode):
...
node = tf.add(tf.matmul(features, w), b)
...
然后,我收到如下错误:
TypeError: Failed to convert object of type <class 'dict'> to Tensor.
Contents: {'education': <tf.Tensor
'random_shuffle_queue_DequeueUpTo:1' shape=(?,) dtype=string>, 'age':
<tf.Tensor 'random_shuffle_queue_DequeueUpTo:2' shape=(?,) dtype=float64> ...
我的问题是如何将features 转换为可用作输入的张量。
希望我已经清楚地描述了这个问题。提前谢谢你。
【问题讨论】:
标签: python tensorflow sparse-matrix