%% 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;

% Create a layer array containing the custom layer preluLayer, attached to this is example as a supporting file. To access this layer, open this example as a live script.

layers = [ 
    imageInputLayer([28 28 1])
    convolution2dLayer(5,20)
    batchNormalizationLayer
    preluLayer(20)
    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 = mean(YTest==YPred)

% Copyright 2017 The MathWorks, Inc.