【问题标题】:What is the difference between concatenate and add in keras?keras中的连接和添加有什么区别?
【发布时间】:2020-03-10 10:18:15
【问题描述】:

我想在 keras 中为我的全卷积网络的内层添加跳过连接,有一个 keras.layers.Add 选项,还有一个 keras.layers.concatenate 选项。

有什么区别?我应该使用哪一个?

【问题讨论】:

    标签: tensorflow keras deep-learning


    【解决方案1】:

    有什么区别?

    添加层添加两个输入张量,而连接添加两个张量。您可以参考此documentation 了解更多信息。

    例子:

    import keras
    import tensorflow as tf
    import keras.backend as K
    
    a = tf.constant([1,2,3])
    b = tf.constant([4,5,6])
    
    add = keras.layers.Add()
    print(K.eval(add([a,b])))
    #output: [5 7 9]
    
    concat = keras.layers.Concatenate()
    print(K.eval(concat([a,b])))
    #output: array([1, 2, 3, 4, 5, 6], dtype=int32)
    

    我应该使用哪一个?

    您可以使用 Add 跳过连接。

    【讨论】:

    • 我也看到了跳过连接的连接..你能解释一下区别吗?例如 x = tf.keras.layers.Concatenate(axis=-1)([x, y])
    • @Khan 老了,但刚刚碰到这个:stackoverflow.com/a/49179305/6301103
    猜你喜欢
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    • 2018-08-24
    • 2018-10-03
    • 2019-09-19
    • 2018-03-11
    • 1970-01-01
    • 2020-06-04
    相关资源
    最近更新 更多