Invalid Transformation in trainNetwork (on pixelLabel​ImageDatas​tore)

조회 수: 49(최근 30일)
Markus Ess
Markus Ess 2019년 8월 20일
댓글: Matthew J 2021년 4월 12일
I am trying to do transfer learning on semantic segmentation with the Deep Learning Toolbox, however I am not sure if I am doing things right.
As I don't have a lot of training data, I am using vgg19 as basis, using 224x224 images. However the images and labels I created with ImageLabeler are of size 1200x1600. Thus I try to transform both the image and pixel label datastores to 224x224, but it doesn't seem to work.
The error I am getting is:
Error using trainNetwork (line 165)
Invalid transform function defined on datastore.
Caused by:
Error using nnet.internal.cnn.util.NetworkDataValidator/assertDatastoreHasResponses (line 120)
Invalid transform function defined on datastore.
Error using imresize
Expected input number 1, A, to be one of these types:
single, double, int8, int16, int32, uint8, uint16, uint32, logical
Instead its type was table.
Here is the code:
%prepare training data from ground truth
[imdsTrain,pxds] = pixelLabelTrainingData(gTruth);
%segnetLayers with e.g. vgg19
imageSize = [224 224 3];
numClasses = 2;
lgraph = segnetLayers(imageSize,numClasses,'vgg19');
%Create a pixel label image datastore for training a semantic segmentation network.
pximds = pixelLabelImageDatastore(imdsTrain,pxds);
%resize the labels and images
targetSize = [224,224];
imdsReSz = transform(pximds,@(x) imresize(x,targetSize));
%Set up training options.
options = trainingOptions('sgdm','InitialLearnRate',1e-3, ...
%Train the network.
net = trainNetwork(imdsReSz,lgraph,options);
What am I doing wrong?


Sourav Bairagya
Sourav Bairagya 2019년 8월 23일
The error you are getting is coming from the use of “imresize” function over pixel-label image datastore object i.e. “pximds”. This “pximds” is of datatype ‘table’and resizing a table cannot be done using “imresize” function. The “imresize”function can only resize objects of numerical (‘single’, ‘double’, ‘int8’, ‘int16’, ‘int32’, ‘uint8’, ‘uint16’, ‘uint32’) or “logical” datatypes.
Now, one option here is to do this resize individually “imdsTrain” and “pxds”. But this is possible only for “imdsTrain” which is an image datastore object. In this case, each path stored in “imdsTrain” leads to an image file (where pixels are either ‘double’ or ‘uint8’ type) and hence, it is possible to resize it.
But, “pxds” is the pixel label datastore object, where each saved path leads to a label image where each pixel is saved as a category. Now, logically you cannot resize this categorical array as here the original pixel values of the corresponding categories are not retained anymore. Hence, resizing of label images are not possible.
Here, you can resize your training dataset to the desired dimension (224,224) before labelling is done. After resizing you can generate the pixel labels using “ImageLabeler”. Then, there will be no need of resizing label images in any intermediate step.
  댓글 수: 3

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by