How to solve "Incorrectly defined MiniBatchable Datastore" error when training network

Viewed 471

I'm trying to use a convolutional neural net (designed with MATLAB's Deep Network Designer) to identify flowers from a dataset of images (pretty new to machine learning, haven't taken a course, just playing around with things). I've stored my images and labels in an augmented datastore called auimds, but when I run trainNetwork, I get the following error:

Error using trainNetwork (line 150) Incorrectly defined MiniBatchable Datastore. Error in read method of C:\Program Files\MATLAB\R2018b\toolbox\matlab\datatypes@table\table.m at line 261: Wrong number of arguments.

Error in trainer (line 2) net = trainNetwork(auimds,lgraph_1,options);

This is the code that produces the error:

options = trainingOptions('sgdm');
net = trainNetwork(auimds,lgraph_1,options);

This is the relevant part of the code that creates auimds. "paths" is a list of paths to images, "labels" is the list of labels, and "folders" is a list of the names of folders containing images. The images are given labels based on their containing folder's name:

counter = 1;
for i=1:length(paths)
    files = dir(fullfile(paths(i),'*.jpg'));
    for j=1:length(files)
        labels(counter) = folders(i).name;
        counter = counter + 1;
    end
end
imds = imageDatastore(paths,'Labels',labels);
auimds = augmentedImageDatastore([200,200],imds);
1 Answers

For anyone encountering this issue, I solved it by setting the labels to categorical.

imds = imageDatastore(paths,'Labels', categorical(labels));
Related