matlab flatten,Flatten layer

Define Network Architecture

Create a classification LSTM network that classifies sequences of 28-by-28 grayscale images into 10 classes.

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.

An LSTM layer with 200 hidden units that outputs the last time step only.

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

To perform the convolutional operations on each time step independently, include a sequence folding layer before the convolutional layers. LSTM layers expect vector sequence input. To restore the sequence structure and reshape the output of the convolutional layers to sequences of feature vectors, insert a sequence unfolding layer and a flatten layer between the convolutional layers and the LSTM layer.

inputSize = [28 28 1];

filterSize = 5;

numFilters = 20;

numHiddenUnits = 200;

numClasses = 10;

layers = [ ...

sequenceInputLayer(inputSize,'Name','input')

sequenceFoldingLayer('Name','fold')

convolution2dLayer(filterSize,numFilters,'Name','conv')

batchNormalizationLayer('Name','bn')

reluLayer('Name','relu')

sequenceUnfoldingLayer('Name','unfold')

flattenLayer('Name','flatten')

lstmLayer(numHiddenUnits,'OutputMode','last','Name','lstm')

fullyConnectedLayer(numClasses, 'Name','fc')

softmaxLayer('Name','softmax')

classificationLayer('Name','classification')];

Convert the layers to a layer graph and connect the miniBatchSize output of the sequence folding layer to the corresponding input of the sequence unfolding layer.

lgraph = layerGraph(layers);

lgraph = connectLayers(lgraph,'fold/miniBatchSize','unfold/miniBatchSize');

View the final network architecture using the plot function.

figure

plot(lgraph)

e14559834a1cafc5072cd5dd02a15252.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值