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.