Can anyone help me with this error?

Error using matlab.io.datastore.ImageDatastore/readimage (line 36)
Error using ReadFcn @(filename)readAndPreprocessImage(filename) function handle for file
E:\IndianCulturalEventRecognition\1\1.jpg.
Undefined function 'readAndPreprocessImage' for input arguments of type 'char'.
Error in CNN_main>@(filename)readAndPreprocessImage(filename)

 Accepted Answer

3 Comments

yes, it still shows the same error,
infact the entire error goes like this:
Error using matlab.io.datastore.ImageDatastore/readimage (line 36)
Error using ReadFcn @(filename)readAndPreprocessImage(filename) function handle for file
D:\IndianCulturalEventRecognition\1\100.jpg.
Undefined function 'readAndPreprocessImage' for input arguments of type 'char'.
Error in CNN_main>@(filename)readAndPreprocessImage(filename)
Error in nnet.internal.cnn.ImageDatastoreDispatcher (line 82)
[this.ExampleImage, exampleInfo] = imageDatastore.readimage(1);
Error in nnet.internal.cnn.DataDispatcherFactory>iCreateImageDatastoreDispatcher (line 35)
dispatcher = nnet.internal.cnn.ImageDatastoreDispatcher( inputs, miniBatchSize, endOfEpoch,
precision );
Error in nnet.internal.cnn.DataDispatcherFactory.createDataDispatcher (line 23)
dispatcher = iCreateImageDatastoreDispatcher( inputs, miniBatchSize,
endOfEpoch, precision );
Error in SeriesNetwork>iParseActivationInputs (line 426)
dispatcher = nnet.internal.cnn.DataDispatcherFactory.createDataDispatcher( ...
Error in SeriesNetwork/activations (line 249)
[dispatcher, params] = iParseActivationInputs(X, precision, varargin{:});
Error in CNN_main (line 17)
trainingFeatures1 = activations(convnet, trainingSet, featureLayer1, ...
My original code:
rootFolder = fullfile( 'E:\MTECH STUFF\2ND YEAR\CBTC\IMPLEMENTATION\P3 PROJECT\CNN CODE & Support\IndianCulturalEventRecognition');
categories = {'1','2'};
imds = imageDatastore(fullfile(rootFolder, categories), 'LabelSource', 'foldernames');
tbl = countEachLabel(imds);
minSetCount = min(tbl{:,2});
imds = splitEachLabel(imds, minSetCount, 'randomize');
countEachLabel(imds);
convnet=helperImportMatConvNet('imagenet-caffe-alex.mat');
disp('CNNhas been loaded');
%imds.ReadFcn = @(filename)readAndPreprocessImage_saliency(filename);
imds.ReadFcn = @(filename)readAndPreprocessImage(filename);
[trainingSet, testSet] = splitEachLabel(imds, 0.6, 'randomize');
featureLayer1 = 'fc7';
featureLayer2= 'fc6';
trainingFeatures1 = activations(convnet, trainingSet, featureLayer1, ...
'MiniBatchSize', 32, 'OutputAs', 'columns');
trainingFeatures2 = activations(convnet, trainingSet, featureLayer2, ...
'MiniBatchSize', 31, 'OutputAs', 'columns');
% trainingFeatures3 = activations(convnet, trainingSet, featureLayer3, ...
% 'MiniBatchSize', 31, 'OutputAs', 'columns');
trainingFeatures = [trainingFeatures1;trainingFeatures2];
trainingLabels = trainingSet.Labels;
%%
testFeatures1 = activations(convnet, testSet, featureLayer1, 'MiniBatchSize',32);
testFeatures2 = activations(convnet, testSet, featureLayer2, 'MiniBatchSize',32);
%testFeatures3 = activations(convnet, testSet, featureLayer3, 'MiniBatchSize',32);
%%
testFeature = [testFeatures1,testFeatures2];
classifier = fitcecoc(trainingFeatures,trainingLabels,'Learners','Linear','Coding','onevsall','ObservationsIn','columns');
predictedLabels = predict(classifier, testFeature);
testLabels = testSet.Labels;
confMat = confusionmat(testLabels, predictedLabels);
confMat2 = bsxfun(@rdivide,confMat,sum(confMat,2));
Thanks, now its working, the problem was with the path.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!