Contenuto principale

La traduzione di questa pagina non è aggiornata. Fai clic qui per vedere l'ultima versione in inglese.

SeriesNetwork

Rete in serie per il Deep Learning (non consigliata)

Gli oggetti SeriesNetwork non sono consigliati. Utilizzare invece gli oggetti dlnetwork. Per ulteriori informazioni, vedere Storico della versione.

Descrizione

Una rete in serie è una rete neurale per il Deep Learning i cui livelli sono disposti uno dopo l’altro. Ha un singolo livello di input e un singolo livello di output.

Creazione

Esistono diversi modi per creare un oggetto SeriesNetwork:

Nota

Per scoprire altre reti preaddestrate, come googlenet e resnet50, vedere Reti neurali profonde preaddestrate.

Proprietà

espandi tutto

proprietà è di sola lettura.

Livelli di rete, specificati come un array di Layer.

proprietà è di sola lettura.

Nomi dei livelli di input, specificati come array di celle dei vettori di carattere.

Tipi di dati: cell

proprietà è di sola lettura.

Nomi dei livelli di output della rete, specificati come array di celle dei vettori di carattere.

Tipi di dati: cell

Funzioni oggetto

activations(Not recommended) Compute deep learning network layer activations
classify(Not recommended) Classify data using trained deep learning neural network
predict(Not recommended) Predict responses using trained deep learning neural network
predictAndUpdateState(Not recommended) Predict responses using a trained recurrent neural network and update the network state
classifyAndUpdateState(Not recommended) Classify data using a trained recurrent neural network and update the network state
resetStateReset state parameters of neural network
plotTracciare l'architettura della rete neurale

Esempi

comprimi tutto

Addestrare la rete per la classificazione di immagini.

Caricare i dati come un oggetto ImageDatastore.

digitDatasetPath = fullfile(matlabroot,'toolbox','nnet', ...
    'nndemos','nndatasets','DigitDataset');
imds = imageDatastore(digitDatasetPath, ...
    'IncludeSubfolders',true, ...
    'LabelSource','foldernames');

Il datastore contiene 10.000 immagini sintetiche di cifre da 0 a 9. Le immagini sono generate applicando trasformazioni casuali a immagini di cifre create con diversi font. L'immagine di ogni cifra è di 28x28 pixel. Il datastore contiene lo stesso numero di immagini per categoria.

Visualizzare alcune delle immagini presenti nel datastore.

figure
numImages = 10000;
perm = randperm(numImages,20);
for i = 1:20
    subplot(4,5,i);
    imshow(imds.Files{perm(i)});
    drawnow;
end

Figure contains 20 axes objects. Axes object 1 contains an object of type image. Axes object 2 contains an object of type image. Axes object 3 contains an object of type image. Axes object 4 contains an object of type image. Axes object 5 contains an object of type image. Axes object 6 contains an object of type image. Axes object 7 contains an object of type image. Axes object 8 contains an object of type image. Axes object 9 contains an object of type image. Axes object 10 contains an object of type image. Axes object 11 contains an object of type image. Axes object 12 contains an object of type image. Axes object 13 contains an object of type image. Axes object 14 contains an object of type image. Axes object 15 contains an object of type image. Axes object 16 contains an object of type image. Axes object 17 contains an object of type image. Axes object 18 contains an object of type image. Axes object 19 contains an object of type image. Axes object 20 contains an object of type image.

Dividere il datastore in modo che ogni categoria del set di addestramento abbia 750 immagini e il set di prova contenga le immagini rimanenti di ciascuna etichetta.

numTrainingFiles = 750;
[imdsTrain,imdsTest] = splitEachLabel(imds,numTrainingFiles, ...
    'randomize');

splitEachLabel divide i file immagine in digitData in due nuovi datastore imdsTrain e imdsTest.

Definire l’architettura della rete neurale convoluzionale.

layers = [ ...
    imageInputLayer([28 28 1])
    convolution2dLayer(5,20)
    reluLayer
    maxPooling2dLayer(2,'Stride',2)
    fullyConnectedLayer(10)
    softmaxLayer
    classificationLayer];

Impostare le opzioni sulle impostazioni predefinite per la discesa stocastica del gradiente con momento. Impostare il numero massimo di epoche a 20 e avviare l'addestramento con una velocità di apprendimento iniziale di 0,0001.

options = trainingOptions('sgdm', ...
    'MaxEpochs',20,...
    'InitialLearnRate',1e-4, ...
    'Verbose',false, ...
    'Plots','training-progress');

Addestrare la rete.

net = trainNetwork(imdsTrain,layers,options);

Figure Training Progress (15-Aug-2023 20:45:20) contains 2 axes objects and another object of type uigridlayout. Axes object 1 with xlabel Iteration, ylabel Loss contains 6 objects of type patch, text, line. Axes object 2 with xlabel Iteration, ylabel Accuracy (%) contains 6 objects of type patch, text, line.

Eseguire la rete addestrata sul set di prova che non è stato utilizzato per addestrare la rete, e prevedere le etichette delle immagini (cifre).

YPred = classify(net,imdsTest);
YTest = imdsTest.Labels;

Calcolare la precisione. L'accuratezza è il rapporto tra il numero di etichette vere nei dati di prova che corrispondono alle classificazioni di classify e il numero di immagini nei dati di prova.

accuracy = sum(YPred == YTest)/numel(YTest)
accuracy = 0.9416

Funzionalità estese

espandi tutto

Cronologia versioni

Introdotto in R2016a

comprimi tutto