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

61 ビュー (過去 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 件)

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by