主要内容

flattenLayer

Flatten layer

描述

一个平坦的层使输入的空间尺寸折叠到通道尺寸中。

为了example, if the input to the layer is anH-经过-W-经过-C-经过-N-经过-Sarray (sequences of images), then the flattened output is an (H*W*C)-经过-N-经过-Sarray.

Creation

描述

= FlatteNlayercreates a flatten layer.

example

= FlatteNlayer('Name',Name)sets the optionalNameproperty using a name-value pair. For example,flattenLayer('Name','flatten1')creates a flatten layer with name'Flatten1'.

Properties

expand all

图层名称,指定为字符向量或字符串标量。为了array input, thetrainNetwork,汇编工作,LayerGraph, 和dlnetwork功能自动将名称分配给具有名称的图层''.

Data Types:char|string

此属性仅阅读。

该层的输入数量。该层仅接受单个输入。

Data Types:double

此属性仅阅读。

层的输入名称。该层仅接受单个输入。

Data Types:细胞

此属性仅阅读。

Number of outputs of the layer. This layer has a single output only.

Data Types:double

此属性仅阅读。

层的输出名称。该层仅具有单个输出。

Data Types:细胞

Object Functions

Examples

collapse all

创建一个具有名称的平坦层'Flatten1'.

层= FlatteNlayer('Name','Flatten1')
层= FlattenLayer with properties: Name: 'flatten1'

为包含图像序列的数据创建深度学习网络,例如视频和医疗图像数据。

  • 要将图像的序列输入到网络中,请使用序列输入层。

  • 要独立应用卷积操作到每个时间步,请首先使用序列折叠层将图像序列转换为图像数组。

  • To restore the sequence structure after performing these operations, convert this array of images back to image sequences using a sequence unfolding layer.

  • To convert images to feature vectors, use a flatten layer.

然后您可以输入向量序列LSTM和BiLSTM layers.

Define Network Architecture

创建一个分类LSTM网络,该网络将28 by-28灰度图像的序列分类为10个类。

Define the following network architecture:

  • A sequence input layer with an input size of[28 28 1].

  • A convolution, batch normalization, and ReLU layer block with 20 5-by-5 filters.

  • 具有200个隐藏单元的LSTM层仅输出最后一个时间步骤。

  • A fully connected layer of size 10 (the number of classes) followed by a softmax layer and a classification layer.

要独立执行每个时间步上的卷积操作,请在卷积层之前包括一个序列折叠层。LSTM层期望矢量序列输入。为了恢复序列结构并将卷积层的输出重塑为特征向量的序列,请在卷积层和LSTM层之间插入序列展开层和平坦的层。

inputSize = [28 28 1]; filterSize = 5; numFilters = 20; numHiddenUnits = 200; numClasses = 10; layers = [...sequenceInputLayer(inputSize,'Name','input')sequenceFoldinglayer('Name','fold')卷积2Dlayer(过滤,数字,'Name','conv') batchNormalizationLayer('Name','bn') reluLayer('Name','relu') sequenceUnfoldingLayer('Name','展开')flattenlayer('Name','flatten') lstmLayer(numHiddenUnits,'OutputMode','last','Name','lstm')完整连接的layerer(numClasses,'Name','FC') softmaxLayer('Name','softmax')分类器('Name','classification');

将图层转换为图层图并连接miniBatchSize序列折叠层输出到序列展开层的相应输入。

lgraph = layerGraph(layers); lgraph = connectLayers(lgraph,'fold/miniBatchSize',“展开/minibatchsize”);

View the final network architecture using theplotfunction.

图(lgraph)

Figure contains an axes object. The axes object contains an object of type graphplot.

算法

expand all

Extended Capabilities

GPU Code Generation
使用GPU CODER™为NVIDIA®GPU生成CUDA®代码。

Version History

Introduced in R2019a