How to give target data in nntool or in nnstart?

5 views (last 30 days)
I have created dataset of 94 B-scan images (76 training + 18 testing) consists of 3 classes (metal pipe, steel box, plastic box). I have extracted statistical features from images the size of training features is 76*6. and I have assigned labels using traindb.Labels, I can able to load input data as training features from work space but Iam unable to load target data.
My goal is to classify the three objects using NN classifier. I have classified these objects using ECOC-SVM but I'm unable to load target data using nntool. I'm attaching my code and database for your reference. please help me.
  1 Comment
santhosh kumar buddepu
santhosh kumar buddepu on 8 Dec 2021
my labels are 76*1 categorical (metal pipe-19, plastic box-28, steel box-29). I need to classify into 3 classes and my target should be 76*3 which is in the form of
1 1 1....1(19) 0 0 0... (remaining)
0 0 0..0(19) 1 1 1...1(28) 0 0...0(remaining)
0 0 0......0(47) 1 1 1...1(29)
how to make target like this? please help me

Sign in to comment.

Answers (1)

Samay Sagar
Samay Sagar on 26 Apr 2024
To load target data for use with a Neural Network classifier, you need to convert your categorical labels into a format that the neural network can understand. This usually means transforming the labels into a one-hot encoded format if you are using a network that outputs class probabilities for each class.
Here is how you can modify your labels:
% Assuming traininglabels is a 76x1 categorical array with categories:
% 'metal pipe', 'plastic box', 'steel box'
% Initialize the target matrix with zeros
numImages = numel(traininglabels); % Number of training images
categoriesList = categories(traininglabels); % Get the list of categories
numClasses = numel(categoriesList); % Number of unique classes
targetMatrix = zeros(numImages, numClasses);
% For each class, set the appropriate entries in the target matrix to 1
for classIndex = 1:numClasses
className = categoriesList{classIndex}; % Access the category name correctly
% Find all rows in traininglabels that belong to the current class
rowsOfClass = traininglabels == className;
% Set the corresponding entries in the target matrix to 1
targetMatrix(rowsOfClass, classIndex) = 1;
end
% Now, targetMatrix is your desired 76x3 target matrix
You can follow a similar approach to prepare your testing target data.
Hope this helps!

Categories

Find more on Recognition, Object Detection, and Semantic Segmentation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!