顺序模型中层的附加参数

我在尝试在顺序模型中使用一个新层,然而,这个层需要一些额外的输入。当模型不是顺序模型时,模型看起来是这样的:

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

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注