首页 > 解决方案 > Tensorflow 层在矩阵维度和 Keras 等效项上的应用

问题描述

我有一个 TensorFlow 代码:

.
.
leaky_relu(tf.matmul(tf.transpose(out2, perm=[0, 2, 1, 3]), tf.transpose(out2, perm=[0, 2, 3, 1])))
.
.

在这里, 的输出tf.matmul具有 的形状(4, 9, 9)。然后我把它喂给leaky_relu一层。

现在我的问题是,如果我使用 Keras 重写它,那么下面的“翻译”是否准确?

.
.
out2 = Lambda(lambda x: K.dot(K.permute_dimensions(x, (0, 2, 1, 3)), K.permute_dimensions(x, (0, 2, 3, 1))), output_shape=(4,9,9))(out2)
out2 = Flatten()(out2)
out2 = Dense(324, kernel_initializer='glorot_normal', activation='linear')(out2)
out2 = LeakyReLU(alpha=.2)(out2)
out2 = Reshape((4, 9, 9))(out2)
.
.

标签: pythontensorflowkeras

解决方案


推荐阅读