根據給定的 feature_columns 返回密集的 Tensor 作為輸入層。
用法
tf.compat.v1.feature_column.input_layer(
features, feature_columns, weight_collections=None, trainable=True,
cols_to_vars=None, cols_to_output_tensors=None
)參數
-
features從鍵到張量的映射。_FeatureColumn通過這些鍵查找。例如numeric_column('price')將查看此字典中的 'price' 鍵。值可以是SparseTensor或Tensor取決於相應的_FeatureColumn。 -
feature_columns一個包含要用作模型輸入的 FeatureColumns 的迭代。所有項目都應該是派生自_DenseColumn的類的實例,例如numeric_column,embedding_column,bucketized_column,indicator_column。如果你有分類特征,你可以用embedding_column或indicator_column包裝它們。 -
weight_collections將添加變量的集合名稱列表。請注意,變量也將添加到集合tf.GraphKeys.GLOBAL_VARIABLES和ops.GraphKeys.MODEL_VARIABLES中。 -
trainable如果True還將變量添加到圖形集合GraphKeys.TRAINABLE_VARIABLES(請參閱tf.Variable)。 -
cols_to_vars如果不None, 必須是一個字典,將填充來自的映射_FeatureColumn列出Variables。例如,在調用之後,我們可能有 cols_to_vars = {_EmbeddingColumn( categorical_column=_HashedCategoricalColumn( key='sparse_feature', hash_bucket_size=5, dtype=tf.string), dimension=10):[ -
cols_to_output_tensors如果不是None,則必須是一個字典,該字典將填充從 '_FeatureColumn' 到關聯輸出Tensor的映射。
返回
-
Tensor表示模型的輸入層。它的形狀是 (batch_size, first_layer_dimension) 並且它的 dtype 是float32。 first_layer_dimension 是根據給定的feature_columns確定的。
拋出
-
ValueError如果feature_columns中的項目不是_DenseColumn。
通常使用 FeatureColumns 說明訓練數據中的單個示例。在模型的第一層,這個麵向列的數據應轉換為單個 Tensor 。
例子:
price = numeric_column('price')
keywords_embedded = embedding_column(
categorical_column_with_hash_bucket("keywords", 10K), dimensions=16)
columns = [price, keywords_embedded, ...]
features = tf.io.parse_example(..., features=make_parse_example_spec(columns))
dense_tensor = input_layer(features, columns)
for units in [128, 64, 32]:
dense_tensor = tf.compat.v1.layers.dense(dense_tensor, units, tf.nn.relu)
prediction = tf.compat.v1.layers.dense(dense_tensor, 1)
相關用法
- Python tf.compat.v1.feature_column.categorical_column_with_vocabulary_file用法及代碼示例
- Python tf.compat.v1.feature_column.make_parse_example_spec用法及代碼示例
- Python tf.compat.v1.feature_column.linear_model用法及代碼示例
- Python tf.compat.v1.feature_column.shared_embedding_columns用法及代碼示例
- Python tf.compat.v1.foldr用法及代碼示例
- Python tf.compat.v1.fixed_size_partitioner用法及代碼示例
- Python tf.compat.v1.foldl用法及代碼示例
- Python tf.compat.v1.flags.BaseListParser用法及代碼示例
- Python tf.compat.v1.flags.FlagHolder用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python tf.compat.v1.Variable.eval用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.compat.v1.layers.conv3d用法及代碼示例
- Python tf.compat.v1.strings.length用法及代碼示例
- Python tf.compat.v1.data.Dataset.snapshot用法及代碼示例
- Python tf.compat.v1.data.experimental.SqlDataset.reduce用法及代碼示例
- Python tf.compat.v1.data.TextLineDataset.from_tensors用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.feature_column.input_layer。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
