%% Include Custom Layer in Network
% You can use a custom layer in the same way as any other layer in Deep Learning Toolbox. This section shows how to create and train a network for sequence classification using the peephole LSTM layer you created earlier.
% Load the example training data.

[XTrain,TTrain] = japaneseVowelsTrainData;

% Define the network architecture. Create a layer array containing a peephole LSTM layer.

inputSize = 12;
numHiddenUnits = 100;
numClasses = 9;

layers = [
    sequenceInputLayer(inputSize)
    peepholeLSTMLayer(numHiddenUnits,inputSize,OutputMode="last")
    fullyConnectedLayer(numClasses)
    softmaxLayer
    classificationLayer];

% Specify the training options and train the network. Train with a mini-batch size of 27 and left-pad the data.

options = trainingOptions("adam",MiniBatchSize=27,SequencePaddingDirection="left");
net = trainNetwork(XTrain,TTrain,layers,options);

% Evaluate the network performance by predicting on new data and calculating the accuracy.

[XTest,TTest] = japaneseVowelsTestData;
YTest = classify(net,XTest,MiniBatchSize=27);
accuracy = mean(YTest==TTest)

% Copyright 2021 The MathWorks, Inc.