原文:https://blog.csdn.net/alxe_made/article/details/80506051
1. 在numpy中concatenate使用
1.1 numpy.concatenate函数定义:
numpy.concatenate((a1, a2, ...), axis=0, out=None)
Parameters:
a1, a2, … :
- sequence of array_like The arrays must have the same shape, except in the dimension corresponding to axis (the first, by default).
axis: - int, optional ,The axis along which the arrays will be joined. Default is 0.
out : - ndarray, optional If provided, the destination to place the result. The shape must be correct, matching that of what concatenate would have returned if no out argument were specified.
1.2 例子:
1.2.1 按照行进行合并
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
np.concatenate((a, b), axis=0) # 这里的axis=0的表示按照行进行合并
输出
array([[1, 2],
[3, 4],
[5, 6]])
1.2.2 按照列进行合并
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
np.concatenate((a, b.T), axis=1) # 这里的axis=1的表示按照列进行合并
输出:
array([[1, 2, 5],
[3, 4, 6]])
2. 深度学习中concatenate函数的使用
在深度学习中,我们也会遇到过需要进行网络层进行连接的地方,结合自己的研究方向,下面举二个例子说明使用这种连接的地方。
2.1 在U-net网络中使用concatenate

具体u-net如何使用可以参考文献[2],这里只是简单介绍concatenate在U-net中的使用。U-net网络是在coding-decoding网络结构基础上发展而来的,他输入的是图像,输出的也是图像,相当于是一个end-to-end[3]网络结构。传统的网络确实可以达到降低网络参数的功能,但是可能重建的效果不是太好,所以我们在deconding将coding过程中相同尺寸的feature map连接到我们decoding网络的feature map,这样就充分了利用了coding网络中结构信息,达到更好的去混迭、或者是重建效果。
2.2 在DenseNet网络中的使用
近几年的深度学习模型中,CNN[4]一直是绝对主导地位。Resnet[7,8]、GoogLeNet[6]、VGG[5]等优秀的网络都是基于CNN搭建的。然而,深层的CNN一直以来都存在一个问题:数据在多层传播后很可能会逐渐消失。Resnet通过“skip connection”结构一定程度上在促进了数据在层间的流通,但接近输出的网络层还是没有充分获得网络前面的特征图。另外提一点,在针对resnet研究,之后出现WRN[9]网络说明了resnets网络可能存在冗余,提出了一个宽而浅的网络,效果证明WRN效果也不错。
在CVPR2017最佳论文Densely Connected Convolutional Networks中作者提出了一个新的DenseNets[10]网络,出发点是为了解决Resnets出现的冗余性问题。使用的参数更少,也缓解了梯度消失的问题,网络也更容易训练。Densenet和ResNests在数学表达的区别就是把Resnets中skip layer加法变成了concatenate连接运算。下面是DenseNets网路结构图:

可见,将skip-layer变成了concatenate层,也就是说后面一层和整个网络前面所有层都建立一个连接,这样会减少网络网络层数,有利于网络的训练。但是具体在使用各种框架实现DenseNets时候,可能会大大的占用显存,作者又提出针对此问题的解决方法[11],解释说这不是DenseNest本身的问题,而是目前的框架比如tensorflow、pytorch等对concatenate操作支持的不是的很好。
问题: cascade级联和concatenate串联区别是什么?
级联将上一系统的输出作为下一系统的输入, 串联将两个系统的输出相加.
网友评论