将可变维数张量与固定维数张量连接

时间:2019-05-15 14:06:34

标签: python tensorflow keras

我正在尝试将形状为(Batch_size=None, context_dim)的上下文向量与形状为LSTM (return_sequence=True)的{​​{1}}隐藏状态输出连接起来

预期输出为 (Batch_size=None, Time_steps=None, feature_dim)

尽管(Batch_size, Time_step, feature_dim+context_dim)暗号没有固定,但我无法使用keras层找到解决方案

我尝试通过 TimeDistributed层来解决此问题,该层应将隐藏状态与上下文张量连接起来。

Time_step

我确实得到了预期的输出形状python inp_seq = Input(shape=(None, FEATURE_DIM,), name="inpt_reference") inp_context = Input(shape=(FEATURE_DIM,), name="last_inpt_reference") hidden_state_0 = LSTM(5, return_sequences=True, name="LSTM")(inp_seq) context_0 = Dense(4, activation='sigmoid', name="dense")(inp_context) expand_0 = TimeDistributed( Lambda(lambda x: concatenate([x, context_0])), name= "spacial_concat" ) context_0_hidden_state = expand_0(hidden_state_0) model_representation = Model(inputs = [inp_seq, inp_context], outputs= context_0_hidden_state) print(model_representation.summary())

  

但是,当我打印模型摘要时,我以某种方式看不到   相对于上下文向量的各层

任何人都知道发生了什么事吗?如果这不是正确的方法,那么是否有任何指向正确方法的指针?

谢谢!

0 个答案:

没有答案
相关问题