Which deep learning model should I use and how should I start using it?
3 views (last 30 days)
Show older comments
I am creating code to convert an image of a beet into a binary mask and then generate a function to predict/calculate the number of rings and their size. I have no problem generating a binary mask or creating a predicted ring using the Image Labeler app. However, I am not sure how to integrate these into a deep learning model, and I am also not sure which model is best for this situation. I have attached one of many sample images below with its expected rings. Below, I also have some sample code, but it is not working properly. Let me know if you have any ideas.
function
trainedNet = trainBinaryMaskUNet(gTruth)
% Define input size for the model
inputSize = [256, 256, 1]; % 1 channel for binary masks
% Access image file names and labels from gTruth
imageFiles = gTruth.DataSource.ImageFileNames; % Adjust this based on gTruth structure
classNames = gTruth.ClassNames; % Class names from gTruth
numClasses = numel(classNames); % Number of classes
% Create an image datastore using the images in gTruth
imds = imageDatastore(imageFiles);
% Create pixel label datastore
pxds = pixelLabelDatastore(gTruth); % Directly using gTruth for pixel labels
% Resize images and masks to the input size
pximds = pixelLabelImageDatastore(imds, pxds, 'OutputSize', inputSize);
% Create U-Net architecture
lgraph = unetLayers(inputSize, numClasses);
% Set training options
options = trainingOptions('adam', ...
'InitialLearnRate', 1e-3, ...
'MaxEpochs', 30, ...
'MiniBatchSize', 8, ...
'Plots', 'training-progress', ...
'Verbose', false);
% Train the model
trainedNet = trainNetwork(pximds, lgraph, options);
disp("Training completed successfully.");
end
% Usage Example
trainedNet = trainBinaryMaskUNet(gTruth);
0 Comments
Accepted Answer
Gayathri
on 5 Nov 2024
Some suggestions for training a segmentation network to segment out the rings in the image are using “unet” and “deeplabv3plus” models.
DeepLab v3+ uses atrous (or dilated) convolutions, which allow the network to capture multi-scale contextual information without losing resolution. This is particularly useful for segmenting objects at various scales.
Please refer to the below link for training a segmentation model using “unet” model.
For more information on how to train a segmentation model using “deeplabv3plus” refer to the following link.
Please note that you need to have a MATLAB R2024a or later version to implement the above-mentioned segmentation models.
Examples for segmenting triangles could be found in the above-mentioned links, which could be adapted for segmenting rings as required for your application.
Hope you find this information helpful.
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!