This repository provides an educational introduction to two of the most important concepts in modern Deep Learning using TensorFlow/Keras:
- Functional API
- Transfer Learning
These techniques are widely used for building flexible neural network architectures and leveraging powerful pre-trained models.
- Why Functional API?
- Sequential vs Functional API
- Advantages of Functional API
- Transfer Learning
- Feature Extraction vs Fine-Tuning
- Popular Pretrained Models
- TensorFlow/Keras Applications
- Understanding the Model Table
- References
The Functional API is an advanced way to build deep learning models in TensorFlow/Keras.
Unlike the Sequential API, it allows developers to create complex architectures where:
- Multiple inputs are possible.
- Multiple outputs are supported.
- Layers can be reused.
- Skip connections can be created.
- Branching architectures become easy.
- Residual networks and attention mechanisms can be implemented naturally.
The Functional API represents the neural network as a Directed Acyclic Graph (DAG) rather than a simple stack of layers.
| Sequential API | Functional API |
|---|---|
| Single input | Multiple inputs |
| Single output | Multiple outputs |
| Linear architecture | Arbitrary graph architecture |
| No skip connections | Supports skip connections |
| Difficult layer sharing | Easy layer reuse |
| Limited flexibility | Highly flexible |
β Flexible network architecture
β Residual Connections (ResNet)
β Dense Connections (DenseNet)
β Multi-input networks
β Multi-output networks
β Siamese Networks
β U-Net
β Autoencoders
β Attention-based architectures
β Easy visualization
Transfer Learning is a machine learning technique where a model trained on a very large dataset is reused as the starting point for another task.
Instead of training millions of parameters from scratch, we leverage knowledge that has already been learned.
Typically:
- Load a pretrained model
- Remove the classification head
- Add new custom layers
- Train only the new layers
- Optionally fine-tune part of the backbone
This significantly reduces:
- Training time
- Required dataset size
- Computational cost
while often improving accuracy.
The pretrained backbone remains frozen.
Pretrained Model
β
Frozen Layers
β
New Dense Layers
β
Prediction
Advantages
- Very fast
- Requires little data
- Prevents overfitting
Some pretrained layers are unfrozen and trained again.
Pretrained Model
β
Partially Trainable Layers
β
New Classification Layers
β
Prediction
Advantages
- Higher accuracy
- Better domain adaptation
- Learns task-specific features
Requires:
- Lower learning rate
- More training time
- Larger dataset
TensorFlow/Keras provides many state-of-the-art pretrained CNN architectures.
Some popular examples include:
| Model | Main Idea |
|---|---|
| MobileNet | Lightweight CNN |
| MobileNetV2 | Inverted Residual Blocks |
| MobileNetV3 | Efficient Mobile Architecture |
| EfficientNet | Compound Scaling |
| EfficientNetV2 | Faster Training |
| ResNet50 | Residual Learning |
| ResNet101 | Deep Residual Network |
| DenseNet121 | Dense Connections |
| DenseNet169 | Dense Connectivity |
| DenseNet201 | Improved Dense Blocks |
| InceptionV3 | Multi-scale Filters |
| InceptionResNetV2 | Inception + Residual |
| NASNetMobile | Neural Architecture Search |
| NASNetLarge | Large NAS Architecture |
| Xception | Depthwise Separable Convolutions |
| VGG16 | Classic CNN |
| VGG19 | Deeper VGG |
| ConvNeXt | Modern CNN Architecture |
Official documentation:
https://keras.io/api/applications/
This page contains all pretrained models available in Keras along with their performance metrics and usage examples.
Inside the Keras Applications page, you'll find a comparison table containing several important metrics.
Understanding these metrics helps you choose the most appropriate model for your project.
| Metric | Description |
|---|---|
| Top-1 Accuracy | Percentage of images whose correct class is the model's highest-confidence prediction. Higher is better. |
| Top-5 Accuracy | Percentage of images where the correct label appears within the five most probable predictions. Commonly used for ImageNet evaluation. |
| Parameters | Total number of trainable parameters. Larger models usually require more memory and computation. |
| Depth | Number of weighted layers in the network. Deeper networks generally learn more complex representations. |
| Size (MB) | Approximate storage size of the pretrained model weights. |
| CPU Inference Time | Average prediction time when running on a CPU. Lower values indicate faster inference. |
| GPU Inference Time | Average prediction time on a GPU. Useful for estimating deployment performance. |
Different applications require different trade-offs.
- MobileNet
- MobileNetV2
- MobileNetV3
- EfficientNetB0
Advantages:
- Small size
- Fast inference
- Low memory usage
- EfficientNetV2
- ConvNeXt
- ResNet101
- DenseNet201
Advantages:
- Better feature extraction
- Higher ImageNet accuracy
- Excellent transfer learning performance
- EfficientNetB0
- EfficientNetB3
- ResNet50
- DenseNet121
These models provide a good compromise between speed and accuracy.
Dataset
β
βΌ
Load Pretrained Model
β
βΌ
Freeze Backbone
β
βΌ
Add New Layers
β
βΌ
Train Classifier
β
βΌ
(Optional)
Fine-Tune Backbone
β
βΌ
Evaluate Model
-
TensorFlow Documentation
https://www.tensorflow.org/ -
Keras Applications
https://keras.io/api/applications/ -
ImageNet Dataset
https://www.image-net.org/ -
TensorFlow Transfer Learning Guide
https://www.tensorflow.org/tutorials/images/transfer_learning
β Star the repository
π΄ Fork it
π Learn
π Build amazing Deep Learning projects!