1
我正在嘗試使用估算器構建LSTM網絡。我的數據看起來像使用估計器構建LSTM網絡
X = [[1,2,3], [2,3,4], ... , [98,99,100]]
y = [2, 3, ... , 99]
我使用的是估算:
regressor = learn.Estimator(model_fn=lstm_model,
params=model_params,
)
其中lstm_model功能
def lstm_model(features, targets, mode, params):
def lstm_cells(layers):
if isinstance(layers[0], dict):
return [tf.nn.rnn_cell.BasicLSTMCell(layer['steps'],state_is_tuple=True) for layer in layers]
return [tf.nn.rnn_cell.BasicLSTMCell(steps, state_is_tuple=True) for steps in layers]
stacked_lstm = tf.nn.rnn_cell.MultiRNNCell(lstm_cells(params['rnn_layers']), state_is_tuple=True)
output, layers = tf.nn.rnn(stacked_lstm, [features], dtype=tf.float32)
return learn.models.linear_regression(output, targets)
,而params是
model_params = {
'steps': 1000,
'learning_rate': 0.03,
'batch_size': 24,
'time_steps': 3,
'rnn_layers': [{'steps': 3}],
'dense_layers': [10, 10]
}
,然後我做配件
regressor.fit(X, y)
我現在面臨的問題是
output, layers = tf.nn.rnn(stacked_lstm, [features], dtype=tf.float32)
需要一個序列,但我不知道怎麼我的功能拆分成張量的列表。 lstm_model函數內部的特徵形狀是(?,3)
我有兩個問題,我該如何分批進行培訓?和我怎麼分割「功能」,因此
output, layers = tf.nn.rnn(stacked_lstm, [features], dtype=tf.float32)
不會引發和錯誤。我正的誤差是
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'Concat' Op have types [float64, float32] that don't all match.
我使用tensorflow 0.12