Machine learning 顺序模型中图层的附加参数

Machine learning 顺序模型中图层的附加参数,machine-learning,neural-network,keras,keras-layer,rnn,Machine Learning,Neural Network,Keras,Keras Layer,Rnn,我试图在顺序模型中使用一个新层,但是,该层需要一些额外的输入。当模型不连续时。模型就像 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], s

我试图在顺序模型中使用一个新层,但是,该层需要一些额外的输入。当模型不连续时。模型就像

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 = 5
model2.add(Dropout(0.5, input_shape=(X.shape[0], X.shape[1])))
我还尝试创建输入序列,并分别在不同的时间戳调用GraphConvolution。 我试过了

但我真的不知道如何独立地处理输入序列的每个输入。因为
input_sequences.shape[0]=None

这个问题很简单,我也曾多次遇到过同样的问题。非常感谢,欢迎回答

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

我有一些解决办法,但不是那么简单。我在输入函数中使用批处理形状:

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'
    )

使用输入序列=输入(批处理形状=(X.shape[0],时间戳,X.shape[1]))

使用
批处理输入形状
似乎是解决您问题的最方便的方法。@MarcinMożejko谢谢@MarcinMożejko您知道如何改进处理每个时间戳的输入并连接它们的过程吗?我当前的实现使用一个列表,然后使用concat,这看起来不那么简单…谢谢!我也有同样的问题,但我仍然不知道该怎么办。
input_sequences = Input(shape=(batch_size, X.shape[0], X.shape[1]),batch_shape=(None, None, None))
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'
    )