The value of 'ValidationData' is invalid. Validation data must be a table, a datastore, or a cell array with input data and responses.

조회 수: 20 (최근 30일)
clear;clc;close all
% Load the Image Dataset of Normal and Malignant WBC
imdsTrain = imageDatastore('D:\Project\DB1\train','IncludeSubfolders',true,'LabelSource','foldernames');
imdsTest = imageDatastore('D:\Project\DB1\test','IncludeSubfolders',true,'LabelSource','foldernames');
%Perform Cross-Validation using Hold-out method with a percentage split of 70% training and 30% testing
%[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
%%
%%
for i=1:numel(imdsTrain.Files)
a=[imdsTrain.Files(i)];
a = imread(char(a));
a = imresize(a,[299 299]);
end
a1=a;
for i=1:numel(imdsTest.Files)
a=[imdsTest.Files(i)];
a = imread(char(a));
a = imresize(a,[299 299]);
end
a2=a;
load('HW');
%%
%Select the Test images and save in Y_test
Y_test = imdsTest.Labels;
%%
% optimzation techniques selection and hyperparamter selection
options = trainingOptions('adam', ...
'MiniBatchSize',16, ...
'MaxEpochs',20, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',a2, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress');
%%
%CNN model training
netTransfer = trainNetwork(a1,HW,options);
%%
% for i=1:numel(imdsValidation.Files)
% a=[imdsValidation.Files(i)];
% a = imread(char(a));
% % featuresTest22 = activations(net,a,layer,'OutputAs','rows');
% YPred(i) = classify(netTransfer,a);
% imshow(a),title(char(YPred));
% i
% end
%%
% CNN Model validation
YPred = classify(netTransfer,a2);
%Performance evaluation of Deep Learning Trained Model
plotconfusion(Y_test,YPred)
Error using trainingOptions (line 269)
The value of 'ValidationData' is invalid. Validation data must be a table, a datastore, or a cell array
with input data and responses.
Error in cnn (line 32)
options = trainingOptions('adam', ...
>>
  댓글 수: 1
源
2023년 3월 29일
Dear sun rise,
Would you solve this problem yet? If possible, could you tell me how to solve it.I have the same problem as you.
Thanks for your help

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2022년 1월 6일
for i=1:numel(imdsTrain.Files)
a=[imdsTrain.Files(i)];
a = imread(char(a));
a = imresize(a,[299 299]);
end
a1=a;
for i=1:numel(imdsTest.Files)
a=[imdsTest.Files(i)];
a = imread(char(a));
a = imresize(a,[299 299]);
end
In those two loops, you process each of a number of files, but you throw away the result of the processing as soon as you start the next loop iteration.
You should consider either using a custom read function for your datastore, or else use a transform store; https://www.mathworks.com/help/matlab/ref/matlab.io.datastore.transform.html
'ValidationData',a2, ...
Your a2 is the result of transforming the very last of your test files only
Use a transform store.
  댓글 수: 2
sun rise
sun rise 2022년 1월 9일
clear;clc;close all
% Load the Image Dataset of Normal and Malignant WBC
imdsTrain = imageDatastore('D:\Project\DB1\train','IncludeSubfolders',true,'LabelSource','foldernames');
imdsTest = imageDatastore('D:\Project\DB1\test','IncludeSubfolders',true,'LabelSource','foldernames');
%Perform Cross-Validation using Hold-out method with a percentage split of 70% training and 30% testing
%[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7,'randomized');
%%
%%
for i=1:numel(imdsTrain.Files)
a=(imdsTrain.Files(i));
targetSize = [299,299];
imdsReSz = transform(imdsTrain,@(x) imresize(x,targetSize));
%imgReSz1 = read(imdsReSz);
%a = imread(char(a));
%a = imresize(a,[299 299]);
end
for i=1:numel(imdsTest.Files)
a=(imdsTest.Files(i));
targetSize1 = [299,299];
imdsReSz1 = transform(imdsTest,@(x) imresize(x,targetSize1));
%a = imread(char(a));
%a = imresize(a,[299 299]);
end
load('HW');
%%
%Select the Test images and save in Y_test
Y_test = imdsReSz1.UnderlyingDatastore.Labels;
%%
% optimzation techniques selection and hyperparamter selection
options = trainingOptions('adam', ...
'MiniBatchSize',16, ...
'MaxEpochs',20, ...
'InitialLearnRate',1e-4, ...
'Shuffle','every-epoch', ...
'ValidationData',imdsReSz1, ...
'ValidationFrequency',3, ...
'Verbose',false, ...
'Plots','training-progress');
%%
%CNN model training
netTransfer = trainNetwork(imdsReSz,HW,options);
%%
% for i=1:numel(imdsValidation.Files)
% a=[imdsValidation.Files(i)];
% a = imread(char(a));
% % featuresTest22 = activations(net,a,layer,'OutputAs','rows');
% YPred(i) = classify(netTransfer,a);
% imshow(a),title(char(YPred));
% i
% end
%%
% CNN Model validation
YPred = classify(netTransfer,imdsReSz1);
%Performance evaluation of Deep Learning Trained Model
plotconfusion(Y_test,YPred)
Error using trainingOptions (line 269) The value of 'ValidationData' is invalid. The datastore used for 'ValidationData' must return a 2-column table or an M-by-2 cell array.
sun rise
sun rise 2022년 1월 10일
Dear Walter Roberson,
Thanks for your advice
Although I tried to use this method, it still throws following error..
Error using trainingOptions (line 269) The value of 'ValidationData' is invalid. The datastore used for 'ValidationData' must return a 2-column table or an M-by-2 cell array.
In addition, my images are grayscale image. In this case, how can i modify my code to apply into inception_v3?
However, I'm very new to programming and not sure how to apply a method to resizing and RGB to grayscale into my code...
Thanks for you in advance!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by