why do I get the error Undefined function or variable 'net'. Error in testalexnet1 (line 16) trainingFeatures = activation​s(net,trai​ningImages​,layer);

I am trying to create my own image data store and this is my code
trainingFeatures = activations(net,trainingImages,layer);

4 件のコメント

Hridya PI
Hridya PI 2017 年 12 月 18 日
I just downloded matlab 2017 trial version .and alexnet too. I have some images of indian coastal fishes to identify. So I created ImageDataStore object and started preparing training and testing images. and the error comes here..
trainingFeatures = activations(net,trainingImages,layer);
Undefined function or variable 'net'.
this is the error it shows. What may be the reason for it?
Walter Roberson
Walter Roberson 2017 年 12 月 18 日
Please show your code before that. In particular, please show your trainNetwork call.
Hridya PI
Hridya PI 2017 年 12 月 18 日
編集済み: Walter Roberson 2017 年 12 月 18 日
imds1 = imageDatastore(fullfile(matlabroot,'toolbox','matlab','images','New Folder'),...
'IncludeSubfolders',true,'FileExtensions','.jpg','LabelSource','foldernames')
%data = read(imds)
Hridya PI
Hridya PI 2017 年 12 月 18 日
編集済み: Walter Roberson 2017 年 12 月 18 日
[trainingImages,testImages] = splitEachLabel(imds1,0.7,'randomized');
numTrainImages = numel(trainingImages.Labels);
idx = randperm(numTrainImages,11);
figure
for i = 1:11
subplot(4,4,i)
I = readimage(trainingImages,idx(i));
imshow(I)
end
layer = 'fc7';
trainingFeatures = activations(net,trainingImages,layer);
testFeatures = activations(net,testImages,layer);
trainingLabels = trainingImages.Labels;
testLabels = testImages.Labels;
classifier = fitcecoc(trainingFeatures,trainingLabels);
predictedLabels = predict(classifier,testFeatures);idx = [1 5 10 15];
figure
for i = 1:numel(idx)
subplot(2,2,i)
I = readimage(testImages,idx(i));
label = predictedLabels(idx(i));
imshow(I)
title(char(label))
end

サインインしてコメントする。

 採用された回答

その他の回答 (1 件)

Hridya PI
Hridya PI 2017 年 12 月 19 日
編集済み: Walter Roberson 2017 年 12 月 19 日
Error using SeriesNetwork/activations (line 794)
'OutputAs' must be 'channels' to use activations on images larger than the network's imageInputLayer.InputSize.
Error in testalexnet1 (line 17)
trainingFeatures = activations(net,trainingImages,layer);
now this is the error .
i changed the line of code as
trainingFeatures = activations(net,trainingImages,layer,'outputAs','channels');
is this right?

7 件のコメント

Walter Roberson
Walter Roberson 2017 年 12 月 19 日
It might be okay; I am not familiar with that function.
Hridya PI
Hridya PI 2017 年 12 月 20 日
編集済み: Hridya PI 2017 年 12 月 20 日
trainingFeatures = activations(net,trainingImages,'fc7','OutputAs','channels');
testFeatures = activations(net,testImages,'fc7','OutputAs','channels');
this code corrected the error.
"Error using classreg.learning.FullClassificationRegressionModel.prepareDataCR (line 192)
X must be a numeric matrix."
What may be the possible reason for this error?
Walter Roberson
Walter Roberson 2017 年 12 月 29 日
Possibly you could get that error if you were passing in a 3D array instead of 2D. 3D would occur for a color image.
Hridya PI
Hridya PI 2017 年 12 月 29 日
Thanks a lot... and also some images exceeded the size of input layer. 227×227×3
Hridya PI
Hridya PI 2017 年 12 月 29 日
Now its fixed
Hridya PI
Hridya PI 2017 年 12 月 30 日
編集済み: Walter Roberson 2017 年 12 月 30 日
Now, I completed the Alexnet Training with my dataset. How I can input an image and make the network predict it? I tried the code below.Butb it takes tha classnames of the pretrained network.Not the classnames that I newly created.
img= imread('D:\as.jpg');
img = imresize(I,[227 227]);
label = classify(net,img)
figure
imshow(img)
title(char(label))
and also the code
net.Layers(end).ClassNames(1:6)
gives the classnames of pretrained network only. What should I do to give an input to the net. Please help

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGet Started with Deep Learning Toolbox についてさらに検索

質問済み:

2017 年 12 月 18 日

編集済み:

2017 年 12 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by