Developing a convolutional neural network from scratch in MATLAB

28 views (last 30 days)
Hi Everyone,
I am trying to understand the architecture of the convolutional neural network (CNN) by developing its algorithm from scratch. First, I developed functions that can perform convolutions and pooling on input images. Then I wanted to feed the outputs of these sequential layers to MATLAB's built-in Neural network models (like fitcnet) to perform image segmentation. I think in CNNs the filters' (kernels') elements are treated like weights in NNet architecture and are determined using an iterative approach. In other words, we just define the total number of filters and let the CNN algorithm calculate the values of their elements.
I don't know how to use MATLAB's NNet models to calculate the filter's elements. Please let me know how this can be implemented in MATLAB. Should I develop the NNet algorithm myself?
I appreciate any help you can provide.

Accepted Answer

Sourabh
Sourabh on 20 Mar 2023
If you want to develop your own Convolutional Neural Network architecture from scratch and train it using MATLAB, you can use the Deep Learning Toolbox.
You can define the architecture of your CNN using the layerGraph object, which allows you to add different types of layers to your network (such as convolutional layers, pooling layers, and fully connected layers).
Once you have defined the architecture of your CNN, you can train it using the trainNetwork function. This function takes as input your training data (images and corresponding labels), your CNN architecture, and training options (such as the optimization algorithm and the number of epochs).
To answer your question about whether you have to develop the neural network algorithm yourself, the answer is no.
MATLAB's Deep Learning Toolbox also provides a variety of pre-defined functions for segmentation tasks, such as the segnetLayers andunetLayers functions. Therefore, it is not necessary to write from scratch and instead you can utilize these functions.
In terms of initializing the filters (kernels) in your CNN, you can either initialize them randomly or use pre-trained filters from a pre-existing network (such as AlexNet or VGG16) and fine-tune them for your specific task.
I hope this helps!
  1 Comment
Memo Remo
Memo Remo on 21 Mar 2023
Thanks, Sourabh! I appreciate your help.
However, I wanted to define everything myself using a simple MATLAB script to fully understand how these deep learning algorithms are working.

Sign in to comment.

More Answers (0)

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!