Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Rafid Mustafiz
Rafid Mustafiz le 5 Mar 2018
Commenté : Walter Roberson le 10 Fév 2020
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 commentaires
Aman Swaraj
Aman Swaraj le 10 Fév 2020
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)

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by