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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!