We are trying to create a wound segmentation model but we keep on getting the following errors when using VGG16
2 次查看(过去 30 天)
显示 更早的评论
We have been trying to figure out what is wrong with our code since we keep on getting the same error for both VGG16 and DeepLabV3
here is our code for VGG16
rgbImagePath = 'TRAINING\IMAGES\PATH';
segImagePath = 'TRAINING\LABELS\PATH';
imdsTrain = imageDatastore(rgbImagePath);
pxdsTrain = pixelLabelDatastore(segImagePath, ["Background", "Foreground"], [0, 1]);
% Convert pixel labels to the proper format
pxdsTrain = pixelLabelImageDatastore(imdsTrain, pxdsTrain);
% Validation
rgbImagePathVal = 'VALIDATION\IMAGES\PATH';
segImagePathVal = 'VALIDATION\LABELS\PATH';
imdsVal = imageDatastore(rgbImagePathVal);
pxdsVal = pixelLabelDatastore(segImagePathVal, ["Background", "Foreground"], [0, 1]);
% Test
rgbImagePathTest = 'TEST\IMAGES\PATH';
imdsTest = imageDatastore(rgbImagePathTest);
net = vgg16;
layers = net.Layers;
layers(end-2:end) = [];
numClasses = 2; % Background and Foreground
layers(end+1) = convolution2dLayer(1, numClasses, 'Name', 'conv6');
layers(end+1) = softmaxLayer('Name', 'softmax');
layers(end+1) = pixelClassificationLayer('Name', 'pixelclass');
% Set the training options
options = trainingOptions('sgdm', ...
'MaxEpochs', 20, ...
'InitialLearnRate', 1e-3, ...
'ValidationData', {imdsVal, pxdsVal}, ...
'ValidationFrequency', 10, ...
'Verbose', true);
% Train the network using the combined datastore
netSeg = trainNetwork(pxdsTrain, layers, options);
pxdsTest = semanticseg(imdsTest, netSeg);
the following errors keep on occuring
Error using trainNetwork
Invalid training or validation response data. Categorical responses must either be a vector or a 2-D matrix or a single-channel 2-D or
3-D image.
Error in TESTVGG2 (line 39)
netSeg = trainNetwork(pxdsTrain, layers, options);
This would be the same case for our DeepLabV3 codes.
1 个评论
mohd akmal masud
2023-7-12
@Julianne Janolino more better you attached link for the data, that can easier to answering the problem.
回答(1 个)
Aman
2023-7-28
Hi,
I understand that you are trying to do image segmentation; for that, you are using the VGG16 and DeepLab v3+ CNN models and getting the invalid training or validation response data error.
As the error suggests, this error occurs when the training data or the validation response data do not match the type of output that the model is producing. The response data means the ground truth label, which is foreground and background in the case of binary image segmentation, and in the case of multi-class segmentation, it would consist of multiple labels, each representing a different class or object.
As the actual data is not present, it is difficult to point out the error upfront, but this issue can be solved by making sure that the response data matches the type of output that the model predicts.
Please refer to the following documentation to learn more about Image Segmentation using the DeepLab v3+ CNN model.
I hope it helps!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!