Invalid training data. Responses must be nonempty when using networkTrain on CNN
显示 更早的评论
Hello,
I'm having issues with the transform of an ImageDatastore when is used as input to the networkTrain method. If I use the original ImageDatastore as input to the networkTrain, everything works as a charm. By using the read method on the transformed datastore and visualizing the images with imshow() I can see that the transform function is doing what is supposed to do (i.e., adding noise to the images in the ImageDatastore). However, when passing the TransformedDatastore to the networkTrain, the following message is thrown:
Error using trainNetwork (line 170)
Invalid training data. Responses must be nonempty.
采纳的回答
If you have image processing toolbox, you may perhaps use denoisingImageDatastore
9 个评论
Thank you Sami. Unfortunately, is more than just noise. I'm trying to change luminance conditions, non-linear streching of the color histograms, etc., so it will be nice to be able to take advantage of the Transformed Datastore, which by the way is doing what I am asking it to do, it's just that networkTraing doesn't like it as input. In fact, if I pass to the networkTrain, the 'transformedDataStore.UnderlyingDatastore' , the networkTrain method smiles and start doing it's job. But, when I pass the 'transformedDataStore' itself to the networkTrain it complains that responses must not be empty, which does not make sense.
Can you check the labels property on the transformed data store
Sami, the transformed data store does not have a Labels property. I believe it relies on the labels stored in the UnderlyingDatastore. I borrowed a simple example from the Matlab help to reproduce the problem. Here it is:
digitDatasetPath = fullfile(matlabroot,'toolbox','nnet', ...
'nndemos','nndatasets','DigitDataset');
imds = imageDatastore(digitDatasetPath, ...
'IncludeSubfolders',true, ...
'LabelSource','foldernames');
numTrainingFiles = 750;
[imdsTrain,imdsTest] = splitEachLabel(imds,numTrainingFiles,'randomize');
layers = [ ...
imageInputLayer([28 28 1])
convolution2dLayer(5,20)
reluLayer
maxPooling2dLayer(2,'Stride',2)
fullyConnectedLayer(10)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm', ...
'MaxEpochs',20,...
'InitialLearnRate',1e-4, ...
'Verbose',false, ...
'Plots','training-progress');
idmsNew = transform(imds,@transformFcn);
net = trainNetwork(idmsNew,layers,options);
function [dataOut]= transformFcn(dataIn)
Gray=dataIn;
%Gray=Gray+20; // do whatever transformation you want to do here
dataOut=Gray;
end
which results in:
Error using trainNetwork (line 170)
Invalid training data. Responses must be nonempty.
Error in test (line 28)
net = trainNetwork(idmsNew,layers,options);
Seems that the read function must output a cell array with input + 1 number of columns.
The last column should contain the responses (Labels).
First you need set includeinfo to true, when calling the transform.
idmsNew = transform(imds,@transformFcn,'IncludeInfo',true);
You will then need to amend your transform function as follows.
function [dataOut,info] = transformFcn(data,info)
if(length(info) > 1)
numRows = length(info);
dataOut = cell(numRows,2);
else
% if readsize = 1
numRows = 1;
data = {data};
end
for idx = 1:numRows
% Randomized 90 degree rotation
imgOut = rot90(data{idx,1},randi(4)-1);
% Return the label from info struct as the
% second column in dataOut.
dataOut(idx,:) = {imgOut,info.Label(idx)};
end
end
See the example at this link below
Perfect !. That works. Thanks.
Hi there, my transforming function actually takes a subset of the entire training image datastore. Can I apply it the same way as you did so that my function creates custom batches during the training process (every time it gets called)? Thanks!
Yes. The structure of the code can potentially be the same.
Great, it worked to me too.
Thanks.
I'm performing affine geometric transformation to volumetric images and MATLAB was also returning such error.
But only one thing I would like to ask to @Carlos is why you transformed all the imds?
Wasn't the purpose of your transformation to augment training data? This way, only imdsTrain would be applied the transformation...
I know there are several purposes to transform data. My question is just out of curiosity...
cheers
hello,
I am also facing the same problem, but the transform function I used is for Image contrast enhancement for brightness preservation based on dynamic streatching.Can you suggest any methods to correct it
Thank You
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
