深度学习中的concatenate使用

1. 在numpy中concatenate使用
1.1 numpy.concatenate函数定义:
numpy.concatenate((a1, a2, ...), axis=0, out=None)
1
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的表示按照行进行合并
1
2
3
输出

array([[1, 2],
       [3, 4],
       [5, 6]])
1
2
3
1.2.2 按照列进行合并
a = np.array([[1, 2], [3, 4]]) 
b = np.array([[5, 6]])
np.concatenate((a, b.T), axis=1)  # 这里的axis=1的表示按照列进行合并
1
2
3
输出:

array([[1, 2, 5],
       [3, 4, 6]])
1
2
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操作支持的不是的很好。

参考文章
python官网
U-Net: Convolutional Networks for Biomedical Image Segmentation
什么是 end-to-end 神经网络?
ImageNet Classification with Deep Convolutional Neural Networks
Very Deep Convolutional Networks for Large-Scale Image Recognition
Going Deeper with Convolutions
Deep Residual Learning for Image Recognition
Identity Mappings in Deep Residual Networks
Wide Residual Networks
Densely Connected Convolutional Networks
Memory-Efficient Implementation of DenseNets
————————————————
版权声明:本文为CSDN博主「alxe_made」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/alxe_made/article/details/80506051

发布了296 篇原创文章 · 获赞 219 · 访问量 54万+

猜你喜欢

转载自blog.csdn.net/qq_36387683/article/details/103381425
今日推荐