Which deep learning model should I use and how should I start using it?
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);
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!