我的输入只是一个包含339732行和两列的csv文件:
我正在尝试在堆叠的LSTM模型上训练我的数据:
data_dim = 29
timesteps = 8
num_classes = 2
model = Sequential()
model.add(LSTM(30, return_sequences=True,
input_shape=(timesteps, data_dim))) # returns a sequence of vectors of dimension 30
model.add(LSTM(30, return_sequences=True)) # returns a sequence of vectors of dimension 30
model.add(LSTM(30)) # return a single vector of dimension 30
model.add(Dense(1, activation='softmax'))
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
model.summary()
model.fit(X_train, y_train, batch_size = 400, epochs = 20, verbose = 1)
Run Code Online (Sandbox Code Playgroud)
这会引发错误:
回溯(最近一次调用最后一次):文件"first_approach.py",第80行,在model.fit中(X_train,y_train,batch_size = 400,epochs = 20,verbose = 1)
ValueError:检查模型输入时出错:预期lstm_1_input有3个维度,但是有形状的数组(339732,29)
我尝试使用重塑我的输入,X_train.reshape((1,339732, 29))但它没有显示错误:
ValueError:检查模型输入时出错:期望lstm_1_input具有形状(无,8,29)但是具有形状的数组(1,339732,29) …
我一直关注这篇文章,以便在我的LSTM模型上实现关注层.
代码attention layer:
INPUT_DIM = 2
TIME_STEPS = 20
SINGLE_ATTENTION_VECTOR = False
APPLY_ATTENTION_BEFORE_LSTM = False
def attention_3d_block(inputs):
input_dim = int(inputs.shape[2])
a = Permute((2, 1))(inputs)
a = Reshape((input_dim, TIME_STEPS))(a)
a = Dense(TIME_STEPS, activation='softmax')(a)
if SINGLE_ATTENTION_VECTOR:
a = Lambda(lambda x: K.mean(x, axis=1), name='dim_reduction')(a)
a = RepeatVector(input_dim)(a)
a_probs = Permute((2, 1), name='attention_vec')(a)
output_attention_mul = merge(
[inputs, a_probs],
name='attention_mul',
mode='mul'
)
return output_attention_mul
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
文件"main_copy.py",第244行,在model = create_model(X_vocab_len,X_max_len,y_vocab_len,y_max_len,HIDDEN_DIM,LAYER_NUM)文件"main_copy.py",第189行,在create_model中attention_mul = attention_3d_block(temp)文件"main_copy.py" ",第124行,注意事项_3d_block a = Permute((2,1))(输入)文件"/root/.virtualenvs/keras_tf/lib/python3.5/site-packages/keras/engine/topology.py",行597,在调用 output_mask = self.compute_mask(inputs,previous_mask)文件"/root/.virtualenvs/keras_tf/lib/python3.5/site-packages/keras/engine/topology.py",第744行,在compute_mask str中( …
我已经在 Ubuntu 16.10 环境中从 Source 安装了 tensorflow。一切都很顺利,但现在在编译程序时,它显示以下错误:
Traceback (most recent call last):
File "ff.py", line 3, in <module>
sess = tf.InteractiveSession()
AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'
Run Code Online (Sandbox Code Playgroud)
没有找到与此相关的帖子。有人可以帮忙吗?