Using neural network in GUI to predict images

1 view (last 30 days)
Hi all,
I'm using neural network with alexnet to predict a set of images with matlab 2017a. I've been testing the predict part with the images from the example page (https://uk.mathworks.com/help/vision/examples/image-category-classification-using-deep-learning.html) but when it comes to predict the example, I get this error when loading the training Features:
Error using SeriesNetwork>iDataDispatcher (line 525) For an image input layer, the input data for predict must be a single image, a 4D array of images, or an imageDatastore with the correct size.
This part is executed when I press a button after I load and resize an image, as shown in the code below:
% --- Executes on button press in identif.
function identif_Callback(hObject, eventdata, handles)
% hObject handle to identif (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global foto net featureLayer trainingSet trainingLabels
img1 = imread(foto);
img2 = imresize(img1, [227,227]);
%%%%
trainingFeatures = activations(net, trainingSet, featureLayer, ...
'MiniBatchSize', 32, 'OutputAs', 'columns','ExecutionEnvironment','cpu'); %Here I get the error
%%%%
%%%%
classifier = fitcecoc(trainingFeatures, trainingLabels, ...
'Learners', 'Linear', 'Coding', 'onevsall', 'ObservationsIn', 'columns');
%%%%
imageFeatures = activations(net, img, featureLayer, 'ExecutionEnvironment','cpu');
%%%%
label = predict(classifier, imageFeatures)
But using it in matlab it does work. So my question is, Do I have to create a separate function to do this?
Thanks in advance and the code of the program is attached.
  1 Comment
sergivaqx
sergivaqx on 6 Nov 2017
Hi all, After checking for a while, I saw the the files loaded at the beginning of the program (trainingSet.m and trainingLabels.m) are loaded as struct, so to use their contents I have to call them as trainingSet.trainingSet and trainingLabels.trainingLabels. At the moment I'm testing it...

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!