我對tensorflow教程如下:https://www.tensorflow.org/tutorials/wide如何將字典轉換爲張量在tensorflow
有許多具有轉換爲稀疏矩陣tf.feature_column.categorical_column_with_vocabulary_list()
類別特徵。
,但我不想使用預定義的估計,
m = tf.estimator.LinearClassifier(
model_dir=model_dir, feature_columns=base_columns + crossed_columns)
我更喜歡使用一個打扮的神經網絡模型,具有:
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
轉換爲可用作輸入的張量。
希望我已經說清楚了這個問題。先謝謝你。
非常感謝您的回覆。但是,如何將轉換後的'features'與'tf.contrib.learn.Estimator'鏈接? – user2413399
@ user2413399答案已更新。 –
謝謝!這有助於很多,並解決了我的問題。 – user2413399