我在尝试在顺序模型中使用一个新层,然而,这个层需要一些额外的输入。当模型不是顺序模型时,模型看起来是这样的:
X_in = Input(shape=(X.shape[1],)) H = Dropout(0.5)(X_in)H = GraphConvolution(16, support, activation='relu', kernel_regularizer=l2(5e-4))([H]+[G])H = Dropout(0.5)(H)Y = GraphConvolution(y.shape[1], support, activation='softmax')([H]+[G])model = Model(inputs=[X_in]+[G], outputs=Y)model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.01))
我尝试使用如下方式的sequential()函数,但不知道如何以这种方式添加层。
model2 = Sequential()batch_size = 5model2.add(Dropout(0.5, input_shape=(X.shape[0], X.shape[1])))
我也尝试创建输入序列并在不同的时间戳上独立调用GraphConvolution。我尝试了
input_sequences = Input(shape=(X.shape[0], X.shape[1]))
还有
input_sequences = Input(shape=(batch_size, X.shape[0], X.shape[1]),batch_shape=(None, None, None))
但我真的不知道如何独立处理输入序列的每个输入。因为input_sequences.shape[0] = None
这个问题非常直接,我多次遇到相同的问题。非常感谢您的帮助,欢迎任何回答。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我得到了一些解决方案,但不是那么直接。我在Input函数中使用了batch_shape:
with tf.name_scope('input_sequence'): input_sequences = Input(batch_shape=(X.shape[0], timestamps, X.shape[1])) gcn_output = [] for i in range(timestamps): gcn_output.append(tf.expand_dims(model([input_sequences[:,i,:]]+[G]),1)) gcn_output_tensor = tf.concat( gcn_output, axis=1, name='concat' )
回答:
使用 input_sequences = Input(batch_shape=(X.shape[0], timestamps, X.shape[1]))