%% 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 digit classification using the PReLU layer you created earlier.
% Load the example training data.

[XTrain,YTrain] = digitTrain4DArrayData;

% Define a custom PReLU layer. To create this layer, save the file preluLayer.m in the current folder. Create a layer array including the custom layer preluLayer.

layers = [ 
    imageInputLayer([28 28 1])
    convolution2dLayer(5,20)
    batchNormalizationLayer
    preluLayer(20,'prelu')
    fullyConnectedLayer(10)
    softmaxLayer
    classificationLayer];

% Set the training options and train the network.

options = trainingOptions('adam','MaxEpochs',10);
net = trainNetwork(XTrain,YTrain,layers,options);

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

[XTest,YTest] = digitTest4DArrayData;
YPred = classify(net,XTest);
accuracy = sum(YTest==YPred)/numel(YTest)

% Copyright 2017 The MathWorks, Inc.