Я использую лямбду для создания слоя самообслуживания, но возникает ошибка, что выход лямбда-слоя не является тензором.
Мой код:
def selfAttention(x):
# input shape [None, n_window_sizes, n_hidden]
temp_transpose = K.transpose(x)
inputs_transpose = K.permute_dimensions(temp_transpose, [2, 0, 1]) # [None, n_hidden, n_window_sizes]
temp_weights = tf.matmul(x, inputs_transpose)
weights = tf.nn.softmax(temp_weights)
output = tf.matmul(weights, x)
return output
Я вызываю лямбда-функцию, как показано ниже:
attention_input = K.stack([lstm[0], lstm[1], lstm[2]], axis = 1)
l_attention = Lambda(selfAttention)(attention_input)