how to plot performance graph for nueral network

5 ビュー (過去 30 日間)
Pramod Rao
Pramod Rao 2018 年 2 月 27 日
回答済み: Parag 2025 年 3 月 6 日
I wanted to plot an performace graph for the following example openExample('nnet/TrainABasicConvolutionalNeuralNetworkForClassificationExample')
please help

回答 (1 件)

Parag
Parag 2025 年 3 月 6 日
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;

カテゴリ

Help Center および File ExchangeDirected Graphs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by