Hello everybody, I need help with a changing color model of pictures in a Image Datastore.
I've tried to change the color model with a transform database.
clc; clear; close all;net = resnet101();%% IMDS
rootFolder = 'cifar100Train';categories = {'Dolphin','Rocket','Bed','Can','Pear'};imds.train = imageDatastore(fullfile(rootFolder, categories), 'LabelSource', 'foldernames');imds.train = splitEachLabel(imds.train, 2 , 'randomize');auimds.train = augmentedImageDatastore(net.Layers(1).InputSize(1:2), imds.train);
Here comes the problem with transformFcn (function is defined below).
dsnew.train = transform(auimds.train, @transformFcn);%% Changing layer of a CNN
lgraph = layerGraph(net);newFCLayer = fullyConnectedLayer(5, 'Name', 'fc5');lgraph = replaceLayer(lgraph,'fc1000',newFCLayer);newClassLayer = classificationLayer('Name','new_classoutput');lgraph = replaceLayer(lgraph,'ClassificationLayer_predictions',newClassLayer);%% Training options
opts = trainingOptions('sgdm', ... 'InitialLearnRate',.001,... 'MaxEpochs',10, ... 'MiniBatchSize',64, ... 'Shuffle','every-epoch', ... 'Plots','training-progress');CNN = trainNetwork(dsnew.train, lgraph, opts);%% Changing color model via the transformFcn
function dataOut = transformFcn(dataIn)dataOut = rgb2hsv(dataIn);end
For color model change I've used rgb2hsv function. Matlab displays this error message:
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.
I would love to find any effective solution for changing color model.
Thank you for any answer!
Martin
Best Answer