how to overcome the following error? errors are described in the comment

조회 수: 3 (최근 30일)
Rafid Mustafiz
Rafid Mustafiz 2018년 3월 5일
댓글: Walter Roberson 2020년 2월 10일
clear all; close all; clc; %deviceInfo = gpuDevice;
rootFolder = fullfile('E:\education\Matlab\bin\Endoscopy\', '101_ObjectCategories'); categories = {'airplanes', 'ferry', 'laptop'};
imds = imageDatastore(fullfile(rootFolder, categories), 'LabelSource', 'foldernames');
tbl = countEachLabel(imds) minSetCount = min(tbl{:,2}); % determine the smallest amount of images in a category
% Use splitEachLabel method to trim the set. imds = splitEachLabel(imds, minSetCount, 'randomize');
% Notice that each set now has exactly the same number of images. countEachLabel(imds)
% Find the first instance of an image for each category airplanes = find(imds.Labels == 'airplanes', 1); ferry = find(imds.Labels == 'ferry', 1); laptop = find(imds.Labels == 'laptop', 1); figure subplot(1,3,1); imshow(readimage(imds,airplanes)) subplot(1,3,2); imshow(readimage(imds,ferry)) subplot(1,3,3); imshow(readimage(imds,laptop))
% Load pre-trained AlexNet net = alexnet() net.Layers
net.Layers(1)
net.Layers(end) % Number of class names for ImageNet classification task numel(net.Layers(end).ClassNames)
imds.ReadFcn = @(filename)readAndPreprocessImage(filename); %% function Iout = readAndPreprocessImage(filename) I = imread(filename); % Some images may be grayscale. Replicate the image 3 times to % create an RGB image. if ismatrix(I) I = cat(3,I,I,I); end % Resize the image as required for the CNN. Iout = imresize(I, [227 227]); % Note that the aspect ratio is not preserved. In Caltech 101, the % object of interest is centered in the image and occupies a % majority of the image scene. Therefore, preserving the aspect % ratio is not critical. However, for other data sets, it may prove % beneficial to preserve the aspect ratio of the original image % when resizing. end %% [trainingSet, testSet] = splitEachLabel(imds, 0.3, 'randomize'); %%
% Get the network weights for the second convolutional layer w1 = net.Layers(2).Weights;
% Scale and resize the weights for visualization w1 = mat2gray(w1); w1 = imresize(w1,5);
% Display a montage of network weights. There are 96 individual sets of % weights in the first layer. figure montage(w1) title('First convolutional layer weights') %% featureLayer = 'fc7'; %% trainingFeatures = activations(net, trainingSet, featureLayer, ... 'MiniBatchSize', 32, 'OutputAs', 'columns','ExecutionEnvironment','cpu'); %% trainingLabels = trainingSet.Labels;
% Train multiclass SVM classifier using a fast linear solver, and set % 'ObservationsIn' to 'columns' to match the arrangement used for training % features. classifier = fitcecoc(trainingFeatures, trainingLabels, ... 'Learners', 'Linear', 'Coding', 'onevsall', 'ObservationsIn', 'columns');
  댓글 수: 5
Aman Swaraj
Aman Swaraj 2020년 2월 10일
can anyone answer his question though? I'm having similar 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)

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Classification Ensembles에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by