I hope I've figured this problem with Transform datastore:
First error
Error using trainNetwork (line 170)
Invalid transform function defined on datastore.
Error in transferlearning (line 37)
CNN = trainNetwork(dsnew.train, lgraph, opts);
Caused by:
Error using nnet.internal.cnn.util.NetworkDataValidator/assertDatastoreHasResponses (line 140)
Invalid transform function defined on datastore.
Error using rgb2hsv>parseInputs (line 95)
MAP must be a Mx3 array.
was figured out by using im2uint8 function.
im2uint8(rgb2hsv(dataIn));
Second error
Error using trainNetwork (line 170)
Invalid training data. Responses must be nonempty.
was figured out thanks to this script in transformFcn file:
function dataOut = transformFcn(dataIn)
B = table2cell(dataIn);
NoImg = size(B,1);
for i=1:NoImg
B{i,1} = im2uint8(rgb2hsv(B{i,1}));
end
dataOut = cell2table(B);
end
In main file:
imds.train = imageDatastore(fullfile(trainDirectoryName, categories), 'LabelSource', 'foldernames');
imds.train = splitEachLabel(imds.train,5, 'randomize');
auimds.train = augmentedImageDatastore(sizeImg, imds.train);
dsnew.train = transform(auimds.train, @transformFcn);
dsnew.train.UnderlyingDatastore.MiniBatchSize = 10;
ReadFcn takes only one image, instead Transform datastore takes whole batch of images (size of this batch is defined in the last line: dsnew.train.UnderlyingDatastore.MiniBatchSize; default is 128).
Hope this helps :-)