a resnet18 adapt to 1-d sequences input design by matlab in matlab

To adapt ResNet18 to 1-D sequence input in Matlab, you can follow these steps:

  1. Load the ResNet18 model using resnet18 function.
main.m
net = resnet18;
16 chars
2 lines
  1. Modify the first layer of the network to accept 1-D sequences input using replaceLayer function.
main.m
inputSize = [1 100]; % 1-D sequence of length 100
newLayers = replaceLayer(net.Layers(1),...
    sequenceInputLayer(inputSize, 'Name', 'input'), 'Name', 'input');
net = assembleNetwork([newLayers; net.Layers(2:end)]);
218 chars
5 lines
  1. Optionally, you can fine-tune the network on your own dataset with trainNetwork function.
main.m
imdsTrain = imageDatastore('trainingSet', ...
    'IncludeSubfolders',true, ...
    'LabelSource','foldernames');
[imdsValidation,imdsTrain] = splitEachLabel(imdsTrain,0.3,'randomized');

options = trainingOptions('sgdm', ...
    'MaxEpochs',40, ...
    'ValidationData',imdsValidation, ...
    'ValidationFrequency',30, ...
    'Verbose',false, ...
    'Plots','training-progress');

net = trainNetwork(imdsTrain, layers, options);
433 chars
14 lines

This will fine-tune the network on your own dataset with Stochastic Gradient Descent with momentum (SGDM).

With these steps, you can adapt ResNet18 to 1-D sequences input in Matlab.

related categories

gistlibby LogSnag