Testing a neural network after training it

22 visualizaciones (últimos 30 días)
Kamyar Mazarei
Kamyar Mazarei el 31 de Jul. de 2021
Respondida: Hari el 3 de Sept. de 2024
hi i have a 2 class problem and im using vgg16 as a convnet to classify
im using deep network designer app and after training it i dont have an option to test it
i have 1000 pics for each class and about 230 as a test
i need to test with these pics and give the results
after i train it i have results and layer in my workshop which i save them
but i have no way to test it
also when i export the network after training and then run it, it just keeps retraining it
does it test it and i dont get it? or im doing something wrong

Respuestas (1)

Hari
Hari el 3 de Sept. de 2024
Hi Kamyar,
I understand that you have trained a VGG16 convolutional neural network using the Deep Network Designer app for a two-class classification problem, but you're unsure how to test it with your test dataset of 230 images.
I assume you have already saved the trained network and have access to the test dataset, and you're looking for a way to evaluate the network's performance on this dataset without retraining.
  • Export the Trained Network: After training in the Deep Network Designer, ensure you export the trained network to the MATLAB workspace. This should provide you with a "trainedNet" variable or similar.
  • Prepare the Test Dataset: Load and preprocess your test images to match the input size of VGG16 (224x224x3) and create an "augmentedImageDatastore".
testFolder = 'path_to_test_images'; % Path to your test images
testImages = imageDatastore(testFolder, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
inputSize = trainedNet.Layers(1).InputSize;
augTestImages = augmentedImageDatastore(inputSize(1:2), testImages);
  • Classify Test Images: Use the "classify" function to predict the labels of your test images using the trained network.
predictedLabels = classify(trainedNet, augTestImages);
trueLabels = testImages.Labels;
  • Evaluate the Model: Calculate the accuracy and other performance metrics using the predicted and true labels.
accuracy = sum(predictedLabels == trueLabels) / numel(trueLabels);
disp(['Test Accuracy: ', num2str(accuracy)]);
  • Visualize Results: Optionally, display test images with predicted and true labels to visually assess the model's performance.
References:
Hope this helps!

Categorías

Más información sobre Deep Learning Toolbox 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