【问题标题】:Concatenation of list of 3-dimensional tensors along a specific axis in Keras在 Keras 中沿特定轴连接 3 维张量列表
【发布时间】:2018-04-29 18:20:54
【问题描述】:
for i in range(y_word_max_len):
    sub_decoder_input = gather(main_decoder,(i))
    # print(sub_decoder_input)
    sub_decoder_input_repeated = RepeatVector(y_char_max_len)(sub_decoder_input)
    sub_decoder = LSTM(256,return_sequences=True,name='sub_decoder')(sub_decoder_input_repeated)
    sub_decoder_output = TimeDistributed(Dense(58,activation='softmax'),name='sub_decoder_output')(sub_decoder)
    sub_decoder_output_reshaped = Reshape((1,y_char_max_len,58))(sub_decoder_output)
    print("Sub decoder output is ",sub_decoder_output_reshaped)

我已经写了上面的 sn-p where y_word_max_len = 9

ma​​in_decoder 是一个形状张量 (None,9,256)

y_char_max_len = 7

58 是我输出的大小 执行 sn-p 后,输出为

子解码器输出为 Tensor("reshape_2/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

子解码器输出为 Tensor("reshape_3/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

子解码器输出为 Tensor("reshape_4/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

子解码器输出为 Tensor("reshape_5/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

子解码器输出为 Tensor("reshape_6/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

子解码器输出为 Tensor("reshape_7/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

子解码器输出为 Tensor("reshape_8/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

子解码器输出为 Tensor("reshape_9/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)

子解码器输出为 Tensor("reshape_10/Reshape:0", shape=(?, 1, 7, 58), dtype=float32)


现在我想将由此获得的所有张量 (9) 连接成单个结果张量

形状 (?,9,7,58)

我怎样才能在 Keras 中实现这一点。 谢谢

【问题讨论】:

    标签: machine-learning tensorflow nlp keras


    【解决方案1】:

    添加一个连接层:

    joined = Concatenate(axis=1)([sub1, sub2, sub3, sub4, sub5....])
    

    为此,最好的办法是创建一个子张量列表并使用循环追加到该列表中:

    subTensors = []
    for ..... :
        #calculations
        subTensors.append(sub_decoder_output_reshaped)
    
    
    joined = Concatenate(axis=1)(subTensors)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 2018-05-31
      • 2018-02-24
      • 2019-08-05
      • 2021-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多