Regarding using trainnet, testnet in binary image classification(size difference between network output and test data output)
Hello, every MATLAB users,
I’m trying to make simple binary classification network
model is designed to check whether the image has certain object or not
input datastore is combined of image datastore and label datastore as shown:
imdsTrain = imageDatastore(trainingDataTbl.imageFileName);
imdsTrain.Labels = trainingDataTbl.existence;
imdsTrain.Labels = categorical(imdsTrain.Labels)
labelsTrain = categorical(trainingDataTbl.existence);
ldsTrain = arrayDatastore(labelsTrain);
cdsTrain = combine(imdsTrain, ldsTrain);
(i know already imdsTrain has label data but i modified to debug the error even it doesn’t matter)
Each labels is one of 2 categories : True, False
Designed network structure is as follows:
fcn = @(X) X(:,:,1);
bClayers = [
imageInputLayer([800 800 3],"Name","imageinput")
functionLayer(fcn, "Name","gray")
convolution2dLayer([5 5],8,"Name","conv","Padding","same")
reluLayer("Name","relu")
maxPooling2dLayer([8 8],"Name","maxpool","Padding","same","Stride",[8 8])
convolution2dLayer([3 3],16,"Name","conv_1","Padding","same")
reluLayer("Name","relu_1")
maxPooling2dLayer([5 5],"Name","maxpool_1","Padding","same","Stride",[5 5])
fullyConnectedLayer(2,"Name","fc")
softmaxLayer("Name","softmax")];
It’s simple CNN structure
I set the options as below:
options = trainingOptions("adam", …
GradientDecayFactor=0.9, …
SquaredGradientDecayFactor=0.999, …
InitialLearnRate=0.001, …
LearnRateSchedule="none", …
MiniBatchSize=1, …
L2Regularization=0.0005, …
MaxEpochs=4, …
BatchNormalizationStatistics="moving", …
DispatchInBackground=false, …
ResetInputNormalization=false, …
Shuffle="every-epoch", …
VerboseFrequency=20, …
CheckpointPath=tempdir);
I set the MiniBatchSize with 1.
Because, I don’t know why but some reason error came up when i execute the trainnet function.
net = trainnet(cdsTrain, bClayers, "crossentropy", options);
the error message is that size of prediction(maybe output of the network) is not same with size of desired value(maybe ground truth label data).
and the desired value size is affected by MiniBatchSize.
I have no idea why this error is occuring.
How Can I Adjust MiniBatchSize or Modify the Code to Run Succesfully??
다음 사용 중 오류가 발생함: validateTrueValues (54번 라인) 예측값 및 목표값의 크기가 일치해야 합니다. 예측값의 크기: 2(C) × 1(B) 목표값의 크기: 2(C) × 16(B)
(This is the Korean error message)
I trained with minibatch size of 1 Anyway.
Another problem happens.
metricValues = testnet(net, cdsTest, "accuracy");
While test the network, Even I make Traindata and Testdata with Same size and same formality,
Code couldn’t run with error message the size between network output and desired value(maybe Test data) should same.
This is korean error message for anyone who can understand:
다음 사용 중 오류가 발생함: testnet (40번 라인)
메트릭 "Accuracy"의 경우 네트워크 출력값과 목표값의 크기가 동일해야 합니다.
How can I fix this code??
I hope anyone could respond my question.
Thank you for reading.Hello, every MATLAB users,
I’m trying to make simple binary classification network
model is designed to check whether the image has certain object or not
input datastore is combined of image datastore and label datastore as shown:
imdsTrain = imageDatastore(trainingDataTbl.imageFileName);
imdsTrain.Labels = trainingDataTbl.existence;
imdsTrain.Labels = categorical(imdsTrain.Labels)
labelsTrain = categorical(trainingDataTbl.existence);
ldsTrain = arrayDatastore(labelsTrain);
cdsTrain = combine(imdsTrain, ldsTrain);
(i know already imdsTrain has label data but i modified to debug the error even it doesn’t matter)
Each labels is one of 2 categories : True, False
Designed network structure is as follows:
fcn = @(X) X(:,:,1);
bClayers = [
imageInputLayer([800 800 3],"Name","imageinput")
functionLayer(fcn, "Name","gray")
convolution2dLayer([5 5],8,"Name","conv","Padding","same")
reluLayer("Name","relu")
maxPooling2dLayer([8 8],"Name","maxpool","Padding","same","Stride",[8 8])
convolution2dLayer([3 3],16,"Name","conv_1","Padding","same")
reluLayer("Name","relu_1")
maxPooling2dLayer([5 5],"Name","maxpool_1","Padding","same","Stride",[5 5])
fullyConnectedLayer(2,"Name","fc")
softmaxLayer("Name","softmax")];
It’s simple CNN structure
I set the options as below:
options = trainingOptions("adam", …
GradientDecayFactor=0.9, …
SquaredGradientDecayFactor=0.999, …
InitialLearnRate=0.001, …
LearnRateSchedule="none", …
MiniBatchSize=1, …
L2Regularization=0.0005, …
MaxEpochs=4, …
BatchNormalizationStatistics="moving", …
DispatchInBackground=false, …
ResetInputNormalization=false, …
Shuffle="every-epoch", …
VerboseFrequency=20, …
CheckpointPath=tempdir);
I set the MiniBatchSize with 1.
Because, I don’t know why but some reason error came up when i execute the trainnet function.
net = trainnet(cdsTrain, bClayers, "crossentropy", options);
the error message is that size of prediction(maybe output of the network) is not same with size of desired value(maybe ground truth label data).
and the desired value size is affected by MiniBatchSize.
I have no idea why this error is occuring.
How Can I Adjust MiniBatchSize or Modify the Code to Run Succesfully??
다음 사용 중 오류가 발생함: validateTrueValues (54번 라인) 예측값 및 목표값의 크기가 일치해야 합니다. 예측값의 크기: 2(C) × 1(B) 목표값의 크기: 2(C) × 16(B)
(This is the Korean error message)
I trained with minibatch size of 1 Anyway.
Another problem happens.
metricValues = testnet(net, cdsTest, "accuracy");
While test the network, Even I make Traindata and Testdata with Same size and same formality,
Code couldn’t run with error message the size between network output and desired value(maybe Test data) should same.
This is korean error message for anyone who can understand:
다음 사용 중 오류가 발생함: testnet (40번 라인)
메트릭 "Accuracy"의 경우 네트워크 출력값과 목표값의 크기가 동일해야 합니다.
How can I fix this code??
I hope anyone could respond my question.
Thank you for reading. Hello, every MATLAB users,
I’m trying to make simple binary classification network
model is designed to check whether the image has certain object or not
input datastore is combined of image datastore and label datastore as shown:
imdsTrain = imageDatastore(trainingDataTbl.imageFileName);
imdsTrain.Labels = trainingDataTbl.existence;
imdsTrain.Labels = categorical(imdsTrain.Labels)
labelsTrain = categorical(trainingDataTbl.existence);
ldsTrain = arrayDatastore(labelsTrain);
cdsTrain = combine(imdsTrain, ldsTrain);
(i know already imdsTrain has label data but i modified to debug the error even it doesn’t matter)
Each labels is one of 2 categories : True, False
Designed network structure is as follows:
fcn = @(X) X(:,:,1);
bClayers = [
imageInputLayer([800 800 3],"Name","imageinput")
functionLayer(fcn, "Name","gray")
convolution2dLayer([5 5],8,"Name","conv","Padding","same")
reluLayer("Name","relu")
maxPooling2dLayer([8 8],"Name","maxpool","Padding","same","Stride",[8 8])
convolution2dLayer([3 3],16,"Name","conv_1","Padding","same")
reluLayer("Name","relu_1")
maxPooling2dLayer([5 5],"Name","maxpool_1","Padding","same","Stride",[5 5])
fullyConnectedLayer(2,"Name","fc")
softmaxLayer("Name","softmax")];
It’s simple CNN structure
I set the options as below:
options = trainingOptions("adam", …
GradientDecayFactor=0.9, …
SquaredGradientDecayFactor=0.999, …
InitialLearnRate=0.001, …
LearnRateSchedule="none", …
MiniBatchSize=1, …
L2Regularization=0.0005, …
MaxEpochs=4, …
BatchNormalizationStatistics="moving", …
DispatchInBackground=false, …
ResetInputNormalization=false, …
Shuffle="every-epoch", …
VerboseFrequency=20, …
CheckpointPath=tempdir);
I set the MiniBatchSize with 1.
Because, I don’t know why but some reason error came up when i execute the trainnet function.
net = trainnet(cdsTrain, bClayers, "crossentropy", options);
the error message is that size of prediction(maybe output of the network) is not same with size of desired value(maybe ground truth label data).
and the desired value size is affected by MiniBatchSize.
I have no idea why this error is occuring.
How Can I Adjust MiniBatchSize or Modify the Code to Run Succesfully??
다음 사용 중 오류가 발생함: validateTrueValues (54번 라인) 예측값 및 목표값의 크기가 일치해야 합니다. 예측값의 크기: 2(C) × 1(B) 목표값의 크기: 2(C) × 16(B)
(This is the Korean error message)
I trained with minibatch size of 1 Anyway.
Another problem happens.
metricValues = testnet(net, cdsTest, "accuracy");
While test the network, Even I make Traindata and Testdata with Same size and same formality,
Code couldn’t run with error message the size between network output and desired value(maybe Test data) should same.
This is korean error message for anyone who can understand:
다음 사용 중 오류가 발생함: testnet (40번 라인)
메트릭 "Accuracy"의 경우 네트워크 출력값과 목표값의 크기가 동일해야 합니다.
How can I fix this code??
I hope anyone could respond my question.
Thank you for reading. binaryclassification, cnn, trainnet, deeplearning, testnet MATLAB Answers — New Questions