用於回歸和分類問題的 Wide & Deep 模型。
用法
tf.keras.experimental.WideDeepModel(
    linear_model, dnn_model, activation=None, **kwargs
)參數
- 
linear_model預製的 LinearModel,其輸出必須與 dnn 模型的輸出相匹配。
- 
dnn_modelatf.keras.Model,其輸出必須與線性模型的輸出相匹配。
- 
activation激活函數。將其設置為 None 以保持線性激活。
- 
**kwargs傳遞給 BaseLayer 的關鍵字參數。在裏麵.允許的關鍵字參數包括name.
屬性
- 
distribute_strategy該模型是在tf.distribute.Strategy下創建的。
- 
layers
- 
metrics_names返回所有輸出的模型顯示標簽。注意: metrics_names僅在keras.Model已根據實際數據進行訓練/評估後可用。inputs = tf.keras.layers.Input(shape=(3,)) outputs = tf.keras.layers.Dense(2)(inputs) model = tf.keras.models.Model(inputs=inputs, outputs=outputs) model.compile(optimizer="Adam", loss="mse", metrics=["mae"]) model.metrics_names []x = np.random.random((2, 3)) y = np.random.randint(0, 2, (2, 2)) model.fit(x, y) model.metrics_names ['loss', 'mae']inputs = tf.keras.layers.Input(shape=(3,)) d = tf.keras.layers.Dense(2, name='out') output_1 = d(inputs) output_2 = d(inputs) model = tf.keras.models.Model( inputs=inputs, outputs=[output_1, output_2]) model.compile(optimizer="Adam", loss="mse", metrics=["mae", "acc"]) model.fit(x, (y, y)) model.metrics_names ['loss', 'out_loss', 'out_1_loss', 'out_mae', 'out_acc', 'out_1_mae', 'out_1_acc']
- 
run_eagerly指示模型是否應立即運行的可設置屬性。即刻地運行意味著您的模型將像 Python 代碼一樣逐步運行。您的模型可能會運行得更慢,但通過單步調用各個層調用,您應該可以更輕鬆地對其進行調試。 默認情況下,我們將嘗試將您的模型編譯為靜態圖以提供最佳執行性能。 
該模型聯合訓練了一個線性模型和一個 dnn 模型。
例子:
linear_model = LinearModel()
dnn_model = keras.Sequential([keras.layers.Dense(units=64),
                             keras.layers.Dense(units=1)])
combined_model = WideDeepModel(linear_model, dnn_model)
combined_model.compile(optimizer=['sgd', 'adam'], 'mse', ['mse'])
# define dnn_inputs and linear_inputs as separate numpy arrays or
# a single numpy array if dnn_inputs is same as linear_inputs.
combined_model.fit([linear_inputs, dnn_inputs], y, epochs)
# or define a single `tf.data.Dataset` that contains a single tensor or
# separate tensors for dnn_inputs and linear_inputs.
dataset = tf.data.Dataset.from_tensors(([linear_inputs, dnn_inputs], y))
combined_model.fit(dataset, epochs)在聯合訓練之前,線性和 dnn 模型都可以單獨進行預編譯和訓練:
例子:
linear_model = LinearModel()
linear_model.compile('adagrad', 'mse')
linear_model.fit(linear_inputs, y, epochs)
dnn_model = keras.Sequential([keras.layers.Dense(units=1)])
dnn_model.compile('rmsprop', 'mse')
dnn_model.fit(dnn_inputs, y, epochs)
combined_model = WideDeepModel(linear_model, dnn_model)
combined_model.compile(optimizer=['sgd', 'adam'], 'mse', ['mse'])
combined_model.fit([linear_inputs, dnn_inputs], y, epochs)相關用法
- Python tf.keras.experimental.WideDeepModel.compute_loss用法及代碼示例
- Python tf.keras.experimental.WideDeepModel.reset_metrics用法及代碼示例
- Python tf.keras.experimental.WideDeepModel.save_spec用法及代碼示例
- Python tf.keras.experimental.WideDeepModel.save用法及代碼示例
- Python tf.keras.experimental.WideDeepModel.compute_metrics用法及代碼示例
- Python tf.keras.experimental.WideDeepModel.compile用法及代碼示例
- Python tf.keras.experimental.SequenceFeatures用法及代碼示例
- Python tf.keras.experimental.LinearModel.save用法及代碼示例
- Python tf.keras.experimental.LinearModel.compile用法及代碼示例
- Python tf.keras.experimental.LinearModel.save_spec用法及代碼示例
- Python tf.keras.experimental.PeepholeLSTMCell用法及代碼示例
- Python tf.keras.experimental.LinearModel.compute_loss用法及代碼示例
- Python tf.keras.experimental.LinearModel用法及代碼示例
- Python tf.keras.experimental.LinearModel.reset_metrics用法及代碼示例
- Python tf.keras.experimental.LinearModel.compute_metrics用法及代碼示例
- Python tf.keras.estimator.model_to_estimator用法及代碼示例
- Python tf.keras.applications.inception_resnet_v2.preprocess_input用法及代碼示例
- Python tf.keras.metrics.Mean.merge_state用法及代碼示例
- Python tf.keras.layers.InputLayer用法及代碼示例
- Python tf.keras.callbacks.ReduceLROnPlateau用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.keras.experimental.WideDeepModel。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
