在这段代码的基础上,将gru换成bigru,并在bigru 后面加入多头注意力机制:def LSTNet(trainX1,trainX2,trainY,config): input1 = Input(shape=(trainX1.

动态 未结 0 71
小小草
小小草 LV1 2023年9月23日 23:40 发表
def LSTNet(trainX1,trainX2,trainY,config): input1 = Input(shape=(trainX1.shape[1], trainX1.shape[2])) conv1 = Conv1D(filters=48, kernel_size=6, strides=1, activation='relu') # for input1 # It's a probelm that I can't find any way to use the same Conv1D layer to train the two inputs, conv2 = Conv1D(filters=48, kernel_size=6 , strides=1, activation='relu') # for input2 conv2.set_weights(conv1.get_weights()) # at least use same weight conv1out = conv1(input1) bigru1out = Bidirectional(CuDNNGRU(64, return_sequences=True))(conv1out) attn1 = MultiHeadAttention(num_heads=4)(bigru1out) attn1 = Dropout(config.dropout)(attn1) input2 = Input(shape=(trainX2.shape[1], trainX2.shape[2])) conv2out = conv2(input2) bigru2out = Bidirectional(CuDNNGRU(64, return_sequences=True))(conv2out) attn2 = MultiHeadAttention(num_heads=4)(bigru2out) attn2 = Dropout(config.dropout)(attn2) bigru_out = concatenate([attn1, attn2]) output = Dense(trainY.shape[1])(bigru_out) #highway 使用Dense模拟AR自回归过程,为预测添加线性成份,同时使输出可以响应输入的尺度变化。 highway_window = config.highway_window #截取近3个窗口的时间维 保留了所有的输入维度 z = Lambda(lambda k: k[:, -highway_window:, :])(input1) z = Lambda(lambda k: K.permute_dimensions(k, (0, 2, 1)))(z) z = Lambda(lambda k: K.reshape(k, (-1, highway_window*trainX1.shape[2])))(z) z = Dense(trainY.shape[1])(z) output = add([output,z]) output = Activation('sigmoid')(output)
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复