Here is an example of how to implement a 1D ResNet in MATLAB using the Deep Learning Toolbox:
main.m1463 chars46 lines
This example defines a 1D ResNet with two residual blocks, each consisting of two convolutional layers with batch normalization and ReLU activations, an addition layer to add the input and output of the first convolutional layer, and a final ReLU activation. The output of the residual blocks is passed through a global average pooling layer and then logits and cross-entropy loss are computed in the fully-connected layer and softmax layer. The model is trained for 20 epochs with Adam optimizer.
Note that the prepareData
function loads and formats the input data in the required format for the trainNetwork
function. In this example, the data is a 3D array of size (numFeatures, numObservations, numClasses)
, where numFeatures
is the number of input features, numObservations
is the number of training samples, and numClasses
is the number of output classes (in this case, 10).
gistlibby LogSnag