顺序模型中层的附加参数
additional parameters for layer in sequential model
我正在尝试在顺序模型中使用一个新层,但是,该层需要一些额外的输入。当模型不是顺序的。模型就像
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 = 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
问题很简单,我遇到过很多次同样的问题。非常感谢,欢迎任何答案。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
我有一些解决方案,但不是那么简单。我在输入函数中使用 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 = 输入(batch_shape=(X.shape[0], 时间戳, X.shape[1]))
我正在尝试在顺序模型中使用一个新层,但是,该层需要一些额外的输入。当模型不是顺序的。模型就像
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 = 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
问题很简单,我遇到过很多次同样的问题。非常感谢,欢迎任何答案。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
我有一些解决方案,但不是那么简单。我在输入函数中使用 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 = 输入(batch_shape=(X.shape[0], 时间戳, X.shape[1]))