【思维导图】tf.keras.layers.Concatenate 用法整理

  • Post author:
  • Post category:其他


T

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

两者定义形式不一样,但效果是一样的


参考文献:https://tensorflow.google.cn/api_docs/python/tf/keras/layers/Concatenate?hl=zh-cn

tf.keras.layers.Concatenate

《tf.keras.layers.Concatenate》

tf.keras.layers.Concatenate(大写)

otf.keras.layers.Concatenate( axis=-1,

kwargs)

Arguments

axis

o Axis along which to concatenate.

连接的轴。



kwargs

ostandard layer keyword arguments.

标准层关键字参数。

oIt takes as input a list of tensors, all of the same shape except for the concatenation axis, and returns a single tensor that is the concatenation of all inputs.

它以一个张量列表作为输入,除了连接轴,所有的形状都是一样的,然后返回一个张量它是所有输入的串联。

o例子

案例一

x = np.arange(20).reshape(2, 2, 5)

oy = np.arange(20, 30).reshape(2, 1, 5)

第一层括号里面两个

第二层括号里面一个

第三层括号里面五个

tf.keras.layers.Concatenate(axis=1)([x, y])

oaxis=1

加在第二层里面

o但也有返回的内容呀?

案例二

x1 = tf.keras.layers.Dense(8)(np.arange(10).reshape(5, 2))x2 = tf.keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2))

concatted = tf.keras.layers.Concatenate()([x1, x2])

oconcatted.shape

tf.keras.layers.concatenate(小写)

otf.keras.layers.concatenate( inputs, axis=-1,

kwargs)

Arguments

inputs

oA list of input tensors (at least 2).

axis

oConcatenation axis.

连接轴



kwargs

oStandard layer keyword arguments.

Returns

A tensor, the concatenation of the inputs alongside axis axis.

o一个张量,输入与轴的连接。

oFunctional interface to the Concatenate layer.

连接层的功能接口。

o案例

x = np.arange(20).reshape(2, 2, 5)

y = np.arange(20, 30).reshape(2, 1, 5)

tf.keras.layers.concatenate([x, y],axis=1)

inputs

oA list of input tensors (at least 2).

axis

oConcatenation axis.

y = np.arange(20, 30).reshape(2, 1, 5)

concatted.shape

x = np.arange(20).reshape(2, 2, 5)

tf.keras.layers.concatenate([x, y],axis=1)

x = np.arange(20).reshape(2, 2, 5)

tf.keras.layers.Concatenate(axis=1)([x, y])

y = np.arange(20, 30).reshape(2, 1, 5)