Main Content

Sequence Classification Using 1-D Convolutions

This example shows how to classify sequence data using a 1-D convolutional neural network.

为了训练深层神经网络以对序列数据进行分类,您可以使用1D卷积神经网络。1D卷积层通过将滑动卷积过滤器应用于1D输入来学习特征。使用1D卷积层比使用复发层要快,因为卷积层可以使用单个操作处理输入。相比之下,复发层必须在输入的时间步骤中迭代。但是,根据网络体系结构和滤波器大小,1-D卷积层可能不像复发层那样性能,这些层可以学习时间步长之间的长期依赖性。

This example uses the Japanese Vowels data set described in [1] and [2]. This example trains a 1-D convolutional neural network to recognize the speaker given time series data representing two Japanese vowels spoken in succession. The training data contains time series data for nine speakers. Each sequence has 12 features and varies in length. The data set contains 270 training observations and 370 test observations.

加载序列数据

加载日本元音训练数据。预测数据是一个包含12个特征长度序列的单元格数组。目标数据是标签“ 1”,“ 2”,...,“ 9”的分类向量,与九个发言人相对应。预测器序列是矩阵,具有12行(每个功能为一行)和不同数量的列(每个时间步长的一列)。

[XTrain,TTrain] = japaneseVowelsTrainData; [XValidation,TValidation] = japaneseVowelsTestData;

View the first few training sequences.

XTrain(1:5)
ans=5×1 cell array{12x20 double} {12x26 double} {12x22 double} {12x20 double} {12x21 double}

Visualize the first time series in a plot. Each line corresponds to a feature.

figure plot(XTrain{1}') xlabel(“时间步长”)title("Training Observation 1")numFeatures = size(XTrain{1},1); legend("Feature "+ string(1:numFeatures),Location="northeastoutside"

Figure contains an axes object. The axes object with title Training Observation 1 contains 12 objects of type line. These objects represent Feature 1, Feature 2, Feature 3, Feature 4, Feature 5, Feature 6, Feature 7, Feature 8, Feature 9, Feature 10, Feature 11, Feature 12.

View the number of classes in the training data.

类=类别(ttrain);numClasses = numel(class)
数字= 9

Define 1-D Convolutional Network Architecture

定义1D卷积神经网络体系结构。

  • 将输入大小指定为输入数据的功能数量。

  • 指定两个1-D卷积,relu和层标准化层的块,其中卷积层的滤波器大小分别为3。分别为第一和第二卷积层指定32和64过滤器。对于两个卷积层,左填充输入使输出具有相同的长度(因果填充)。

  • To reduce the output of the convolutional layers to a single vector, use a 1-D global average pooling layer.

  • To map the output to a vector of probabilities, specify a fully connected layer with an output size matching the number of classes, followed by a softmax layer and a classification layer.

过滤= 3;numfilters = 32;层= [...sequenceInputlayer(numfeatures)卷积1Dlayer(过滤,numfilters,padding =“因果”)reluLayer layerNormalizationLayer convolution1dLayer(filterSize,2*numFilters,Padding=“因果”)relulayer layernormalizationlayer globalavericepooling1dlayer plullconnectedlayer(numClasses)soft -maxlayer classificationlayer];

指定培训选项

指定培训选项:

  • Train using the Adam optimizer.

  • Train with a mini-batch size of 27 for 15 epochs.

  • Left-pad the sequences.

  • 使用验证数据验证网络。

  • 监视图中的训练进度并抑制详细的输出。

minibatchsize = 27;选项=训练(“亚当”,,,,...minibatchsize = minibatchsize,...MaxEpochs=15,...semencePaddingDirection =“剩下”,,,,...验证data = {xvalidation,tvalidation},...情节=“训练过程”,,,,...冗长= 0);

火车网络

使用指定的培训选项培训网络火车网功能。

net = trainnetwork(Xtrain,ttrain,layers,options);

Figure Training Progress (26-Feb-2022 11:02:57) contains 2 axes objects and another object of type uigridlayout. Axes object 1 contains 8 objects of type patch, text, line. Axes object 2 contains 8 objects of type patch, text, line.

Test Network

Classify the validation data using the same mini-batch size and sequence padding options used for training.

ypred =分类(net,xvalidation,...minibatchsize = minibatchsize,...semencePaddingDirection =“剩下”);

计算预测的分类精度。

ACC =平均值(ypred == TVALIDATION)
ACC = 0.9568

Visualize the predictions in a confusion matrix.

confusionchart(TValidation,YPred)

Figure contains an object of type ConfusionMatrixChart.

References

[1] Kudo,Mineichi,Jun Toyama和Masaru Shimbo。“使用传递区域的多维曲线分类。”图案识别字母20,否。11–13(1999年11月):1103–11。https://doi.org/10.1016/S0167-8655(99)00077-X

[2] Kudo,Mineichi,Jun Toyama和Masaru Shimbo。“日本元音数据集。”由UCI机器学习存储库分发。https://archive.ics.uci.edu/ml/datasets/japanese+vowels

也可以看看

|||||||

Related Topics