我刚开始使用Tensorflow,当我调用m.fit(input_fn=lambda: self.input_fn(train_data), steps=train_steps)
时,我收到以下错误。
File "/Library/Python/2.7/site-packages/tensorflow/contrib/layers/python/layers/feature_column_ops.py", line 161, in _input_from_feature_columns
transformed_tensor = transformer.transform(column)
File "/Library/Python/2.7/site-packages/tensorflow/contrib/layers/python/layers/feature_column_ops.py", line 882, in transform
feature_column.insert_transformed_feature(self._columns_to_tensors)
File "/Library/Python/2.7/site-packages/tensorflow/contrib/layers/python/layers/feature_column.py", line 991, in insert_transformed_feature
self.sparse_id_column.insert_transformed_feature(columns_to_tensors)
File "/Library/Python/2.7/site-packages/tensorflow/contrib/layers/python/layers/feature_column.py", line 572, in insert_transformed_feature
name="lookup")
File "/Library/Python/2.7/site-packages/tensorflow/contrib/lookup/lookup_ops.py", line 1018, in index_table_from_tensor
"integer" if dtype.is_integer else "non-integer", keys.dtype))
ValueError: Expected non-integer, got <dtype: 'int32'>.
在我传递给fit()
的功能列中,只有int32
和int64
,但这应该不是问题,是吗?
答案 0 :(得分:1)
我认为您可能会在tf.SparseTensor
使用分类功能但您的功能列包含int32
。
在这种情况下,只需将整数列转换为字符串,例如:
# using Pandas
for f in categorical_features:
df_train[f] = df_train[f].astype(str)
df_test[f] = df_test[f].astype(str)