DenseNet121 Model Implementation

Shamim Mahbub
2 min readAug 12, 2020

--

Recently, I am doing my undergraduate thesis on Diabetic Retinopathy. In order to classify the retinal fundus images, I had to train an architecture for my image dataset. In my image dataset, there are two types of images- one of them is “Normal” and the other one is “Exudates” or “Abnormal”.

So, I decided to feed the dataset into the DenseNet121 model. Because this model is newly discovered. It has also shown an eye-catching accuracy. DenseNet concatenates the output of the previous layer and adds it with the upcoming layer.

Fig- Proposed DenseNet Architecture

Implementation

First of all, I have imported all the required libraries and run the cell in Jupyter Notebook.

After running this cell, load the dataset and rescale the images using ImageDataGenerator to 255 pixels. Also, define the target size of the images for the DenseNet model.

Now, call the DenseNet121 model using Keras applications.

Then, I have used the output of the first 3 layers to last layers of the model and store it into variable x. For the activation, I have used the Softmax activation function.

Now, I freeze the weights of all the layers except for the last nine(9) layers. That’s mean the last nine layers of the model will be trained for this classification.

Here is the model summary,

Now, compile and fit the model-

Output

Here is the result of the training & validation accuracy-

From this above image, we can see that, there is an increased accuracy for both training & validation.

Conclusion

In this article, I have tried to implement a DenseNet121 model. This is my first article on Medium. Please let me know if you find this article informative for your work. Thank you.

--

--

Shamim Mahbub

Hi! I am shamim. I am very much enthusiast to Data Science.