how to plot performance graph for nueral network

2 visualizaciones (últimos 30 días)
Pramod Rao
Pramod Rao el 27 de Feb. de 2018
Respondida: Parag el 6 de Mzo. de 2025
I wanted to plot an performace graph for the following example openExample('nnet/TrainABasicConvolutionalNeuralNetworkForClassificationExample')
please help

Respuestas (1)

Parag
Parag el 6 de Mzo. de 2025
Hi, I see you want to plot a performance graph for your convolutional neural network (CNN) training process. MATLAB provides built-in functionality to visualize training performance using the training-progress plot in trainingOptions. However, if you want a custom plot, you can extract training and validation accuracy/loss from the training information and plot them separately.
Steps to Plot Performance Graph
  1. Extract training and validation accuracy from the trainnet output.
  2. Extract training and validation loss.
  3. Plot accuracy and loss over epochs.
MATLAB Code for Performance Graph
% Train the network and store training information
[net, trainInfo] = trainnet(imdsTrain, layers, "crossentropy", options);
% Extract accuracy and loss
trainAccuracy = trainInfo.Metrics.TrainingAccuracy;
valAccuracy = trainInfo.Metrics.ValidationAccuracy;
trainLoss = trainInfo.Metrics.TrainingLoss;
valLoss = trainInfo.Metrics.ValidationLoss;
epochs = 1:length(trainAccuracy); % Epoch numbers
% Plot Training and Validation Accuracy
figure;
subplot(2,1,1);
plot(epochs, trainAccuracy, '-o', 'LineWidth', 2);
hold on;
plot(epochs, valAccuracy, '-s', 'LineWidth', 2);
title('Training and Validation Accuracy');
xlabel('Epoch');
ylabel('Accuracy');
legend('Training Accuracy', 'Validation Accuracy');
grid on;
% Plot Training and Validation Loss
subplot(2,1,2);
plot(epochs, trainLoss, '-o', 'LineWidth', 2);
hold on;
plot(epochs, valLoss, '-s', 'LineWidth', 2);
title('Training and Validation Loss');
xlabel('Epoch');
ylabel('Loss');
legend('Training Loss', 'Validation Loss');
grid on;

Categorías

Más información sobre Directed Graphs en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by