Slicing Pre-Trained models in Keras. Part (II.A)
Mohamed Ibrahim
Doctoral student @ The University of Bonn | Uncertainty Quantification and Explainable Machine Learning for Crop Monitoring
Hi again!
So this is the second part of this series, in which we will understand how to split or slice a pre-trained vision model.
First of all, I selected DenseNet169 pre-trained on ImageNet data as an example for two reasons:
- This was the architecture that was exploited during my MSc studies.
- The architecture follows a dense connectivity pattern, which created a challenging task to split the blocks without violating the original computational graph.
let's begin!
what is DenseNets?
DenseNet is a family of Convolutional Neural networks (CNN) that was built upon the idea of connecting layers using dense connections. It was introduced in 2016 by Gao Huang et al [1] in a paper under the title "Densely Connected Convolutional Networks". He and his team mentioned, "DenseNets have several compelling advantages: they alleviate the vanishing gradient problem, strengthen feature propagation, encourage feature reuse, and substantially reduce the number of parameters.", For my MSc problem DenseNet achieved good results with faster inference and training time. Let's move to the structure of the network.
Network's configuration
It consists of mainly two major blocks:
- Dense Block (DB)
- Transition Block (TB)
领英推è
The objective now is to slice this network at any location, so anyone can use a part of this pre-trained model or any other model. What we will do here can be transferred to another network's architecture such as Inception and ResNets.
As an example, I just want this part of the network to be exploited as a generic feature extractor in your new architecture.
Dealing with the architecture as a Lego brick offers more flexibility if you want to test new ideas.
The steps we will follow:
- Check the original computational graph.
- Understand the architectural design.
- Start splitting your model into smaller blocks.
- Reconnect the blocks again and verify that after reconnection it remains the same as the original one.
Happy learning!?
Thank you.
References
ML and AI engineer
2 å¹´Amazing work ??