我有一个 2D 输入(如果考虑样本数量,则为 3D),我想应用一个 keras 层来接收这个输入并输出另一个 2D 矩阵。因此,例如,如果我有一个大小为 (ExV) 的输入,则学习权重矩阵将是 (SxE) 和输出 (SxV)。我可以用密集层做到这一点吗?
编辑(纳西姆请求):
第一层什么都不做。只是给 Lambda 层一个输入:
from keras.models import Sequential
from keras.layers.core import Reshape,Lambda
from keras import backend as K
from keras.models import Model
input_sample = [
[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]]
,[[21,22,23,24,25],[26,27,28,29,30],[31,32,33,34,35],[36,37,38,39,40]]
,[[41,42,43,44,45],[46,47,48,49,50],[51,52,53,54,55],[56,57,58,59,60]]
]
model = Sequential()
model.add(Reshape((4,5), input_shape=(4,5)))
model.add(Lambda(lambda x: K.transpose(x)))
intermediate_layer_model = Model(input=model.input,output=model.layers[0].output)
print "First layer:"
print intermediate_layer_model.predict(input_sample)
print ""
print "Second layer:"
intermediate_layer_model = Model(input=model.input,output=model.layers[1].output)
print intermediate_layer_model.predict(input_sample)