Invalid training or validation response data
3 views (last 30 days)
Show older comments
Hello, I am training a neural network with semantic segmentation data and I have the following error:
Error using trainNetwork (line 184)
Maximum variable size allowed on the device is exceeded.
Error in index (line 48)
net = trainNetwork(trainingData,layers,opts);
Caused by:
Error using gpuArray
Maximum variable size allowed on the device is exceeded.
I believe this is because the input sizes of my images are quite high: imageInputLayer([8000 6000 3])
I used a @customreader function to resize the images in my imageDatastore and pixelLabelDatastore as follows: imds.ReadFcn = @customreader; and pxds.ReadFcn = @customreader;
However, it is returning the following error:
Error using trainNetwork (line 184)
Invalid training or validation response data. Categorical responses must
either be a vector or a single-channel 2-D or 3-D image.
Error in index (line 48)
net = trainNetwork(trainingData,layers,opts);
I'll leave the code I'm using:
clear, clc, close all;
%% Upload a set of images for training
imds = imageDatastore('Imagens');
imds.ReadFcn = @customreader;
I = readimage(imds,1);
%% Load pixel label images using pixelLabelDatastore
pxDir = fullfile('PixelLabelData');
classNames = ["Escala" "Fundo"];
pixelLabelID = [1 2];
pxds = pixelLabelDatastore(pxDir,classNames,pixelLabelID);
pxds.ReadFcn = @customreader;
C = readimage(pxds,1);
%% Create a binary mask
buildingMask = C == 'Escala';
%figure
%imshowpair(I, buildingMask,'montage')
%% Create a semantic segmentation network
numFilters = 64;
filterSize = 3;
numClasses = 2;
layers = [
imageInputLayer([8000 6000 3])
convolution2dLayer(filterSize,numFilters,'Padding',1)
reluLayer()
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(filterSize,numFilters,'Padding',1)
reluLayer()
transposedConv2dLayer(4,numFilters,'Stride',2,'Cropping',1);
convolution2dLayer(1,numClasses);
softmaxLayer()
pixelClassificationLayer()
];
opts = trainingOptions('sgdm', ...
'InitialLearnRate',1e-3, ...
'MaxEpochs',100, ...
'MiniBatchSize',64);
trainingData = combine(imds,pxds);
net = trainNetwork(trainingData,layers,opts);
The function to resize imageDatastore and pixelLabelDatastore:
function data = customreader(filename)
onState = warning('off', 'backtrace');
c = onCleanup(@() warning(onState));
data = imread(filename);
data = data(:,:,min(1:3, end));
data = imresize(data, [100 75]);
end
I'll also leave a folder on the drive with all the files I'm using:
If you can help me, I will be very grateful.
0 Comments
Answers (0)
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!