14. Keras Sequential and Functional API¶
Learn how to design Deep Learning models using Keras's Sequential and Functional APIs, understand when each approach should be used, build complex computation graphs, work with multiple inputs and outputs, reuse layers, implement skip connections, and design production-ready neural network architectures.
๐ฏ Learning Objectives¶
After completing this chapter, you will be able to:
- Understand the Keras Sequential API
- Understand the Keras Functional API
- Compare Sequential and Functional model construction
- Build simple neural networks using Sequential
- Build complex neural networks using the Functional API
- Understand Keras symbolic tensors
- Understand the relationship between inputs, layers, and outputs
- Build models with multiple inputs
- Build models with multiple outputs
- Reuse layers across different parts of a model
- Build branching architectures
- Build merging architectures
- Implement skip connections
- Understand residual-style connections
- Inspect Functional API model graphs
- Visualize model architecture
- Share layers between models
- Build reusable model components
- Understand model composition
- Understand when to choose Sequential, Functional API, or subclassing
- Design maintainable Keras architectures for enterprise Deep Learning systems
๐ Overview¶
Keras provides multiple ways to define neural network models.
The three major approaches are:
Sequential API
โ
โโโ Simple linear stacks
โ
Functional API
โ
โโโ Complex computation graphs
โ
Model Subclassing
โ
โโโ Maximum customization
The first two approaches are especially important for most Deep Learning applications.
flowchart TD
KERAS["Keras Model Construction"]
KERAS --> SEQ["Sequential API"]
KERAS --> FUNC["Functional API"]
KERAS --> SUB["Model Subclassing"]
SEQ --> SIMPLE["Simple Layer Stack"]
FUNC --> COMPLEX["Complex Graphs"]
SUB --> CUSTOM["Custom Architecture / Behavior"]
๐ง Why Multiple Model APIs?¶
Different neural networks have different architectural requirements.
A simple classifier may look like:
A more complex architecture may look like:
โโโ Dense โโโ
Input โโโโโโโโค โโโ Merge โโ Output
โโโ Dense โโโโ
A residual network may contain:
Input โโโโโโโโโโโโโโโโโ
โ โ
Layer โ
โ โ
Layer โ
โ โ
โโโโโโโ Add โโโโโโโโโ
The Sequential API is ideal for the first case.
The Functional API is designed for the second and third cases.
๐ Sequential API¶
The Sequential API represents a simple linear stack of layers.
flowchart LR
INPUT["Input"]
L1["Dense"]
L2["Dense"]
L3["Dense"]
OUTPUT["Output"]
INPUT --> L1
L1 --> L2
L2 --> L3
L3 --> OUTPUT
Each layer receives the output of the previous layer.
๐งช Basic Sequential Model¶
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.Input(
shape=(784,)
),
tf.keras.layers.Dense(
128,
activation="relu"
),
tf.keras.layers.Dense(
64,
activation="relu"
),
tf.keras.layers.Dense(
10,
activation="softmax"
)
])
The architecture is:
๐ง Sequential Model Concept¶
The Sequential API can be viewed as:
[ f(x) = f_n( f_{n-1}( ... f_2( f_1(x) ) ... ) ) ]
Each layer transforms the output of the previous layer.
๐งฑ Adding Layers¶
Layers can also be added incrementally.
model = tf.keras.Sequential()
model.add(
tf.keras.Input(
shape=(784,)
)
)
model.add(
tf.keras.layers.Dense(
128,
activation="relu"
)
)
model.add(
tf.keras.layers.Dense(
10,
activation="softmax"
)
)
๐ง When Sequential Works Well¶
Use Sequential when:
- The architecture is linear
- There is one input
- There is one output
- Every layer has exactly one input
- Every layer produces exactly one output
- There are no branching paths
- There are no skip connections
Typical examples:
โ Sequential API Limitations¶
Sequential becomes unsuitable when the architecture contains:
For these architectures, use the Functional API.
๐ง Functional API¶
The Functional API represents a neural network as a directed computation graph.
Instead of saying:
we explicitly connect tensors:
and finally create:
๐ Functional API Architecture¶
flowchart LR
INPUT["Input Tensor"]
D1["Dense 128"]
D2["Dense 64"]
OUT["Output"]
INPUT --> D1
D1 --> D2
D2 --> OUT
The important difference is that the engineer explicitly defines the graph.
๐งช Basic Functional API Model¶
import tensorflow as tf
inputs = tf.keras.Input(
shape=(784,)
)
x = tf.keras.layers.Dense(
128,
activation="relu"
)(inputs)
x = tf.keras.layers.Dense(
64,
activation="relu"
)(x)
outputs = tf.keras.layers.Dense(
10,
activation="softmax"
)(x)
model = tf.keras.Model(
inputs=inputs,
outputs=outputs
)
๐ง Functional API Mental Model¶
Think of:
as the starting node.
Each layer:
creates a new tensor.
Finally:
becomes the endpoint.
flowchart LR
INPUT["inputs"]
L1["Layer 1"]
T1["Tensor"]
L2["Layer 2"]
T2["Tensor"]
OUT["outputs"]
INPUT --> L1
L1 --> T1
T1 --> L2
L2 --> T2
T2 --> OUT
๐ง Symbolic Tensors¶
When using the Functional API:
inputs represents a symbolic tensor describing the expected computation.
It is not an actual batch of training data.
This distinction is important.
During training:
๐ง Sequential vs Functional¶
| Feature | Sequential | Functional |
|---|---|---|
| Simple layer stack | โ | โ |
| One input | โ | โ |
| One output | โ | โ |
| Multiple inputs | โ | โ |
| Multiple outputs | โ | โ |
| Branching | โ | โ |
| Skip connections | โ | โ |
| Layer sharing | โ | โ |
| Complex graph | โ | โ |
| Easy to read | โ | โ |
| Complex architectures | โ | โ |
๐ Branching Architecture¶
Suppose an input should pass through two different paths.
flowchart TD
INPUT["Input"]
INPUT --> PATH1["Path 1<br>Dense 128"]
INPUT --> PATH2["Path 2<br>Dense 64"]
PATH1 --> MERGE["Concatenate"]
PATH2 --> MERGE
MERGE --> OUTPUT["Output"]
This cannot naturally be represented as a simple Sequential stack.
The Functional API handles it directly.
๐งช Branching Example¶
inputs = tf.keras.Input(
shape=(100,)
)
branch_1 = tf.keras.layers.Dense(
128,
activation="relu"
)(inputs)
branch_2 = tf.keras.layers.Dense(
64,
activation="relu"
)(inputs)
merged = tf.keras.layers.Concatenate()(
[
branch_1,
branch_2
]
)
outputs = tf.keras.layers.Dense(
10,
activation="softmax"
)(merged)
model = tf.keras.Model(
inputs=inputs,
outputs=outputs
)
๐ง Concatenation¶
Concatenation joins tensors along a specified dimension.
Conceptually:
The resulting tensor can then be passed to another layer.
๐ Add vs Concatenate¶
Two common merging operations are:
Add¶
Requires compatible shapes.
Concatenate¶
Combines feature dimensions.
๐งช Add Example¶
x1 = tf.keras.layers.Dense(
128
)(inputs)
x2 = tf.keras.layers.Dense(
128
)(inputs)
merged = tf.keras.layers.Add()(
[
x1,
x2
]
)
The two tensors must have compatible shapes.
๐ง Skip Connections¶
Skip connections allow information to bypass one or more layers.
flowchart TD
INPUT["Input"]
L1["Layer 1"]
L2["Layer 2"]
ADD["Add"]
INPUT --> L1
L1 --> L2
L2 --> ADD
INPUT --> ADD
ADD --> OUTPUT["Output"]
Mathematically:
[ y=F(x)+x ]
This is a core idea behind residual networks.
๐งช Skip Connection Example¶
inputs = tf.keras.Input(
shape=(128,)
)
x = tf.keras.layers.Dense(
128,
activation="relu"
)(inputs)
x = tf.keras.layers.Dense(
128
)(x)
x = tf.keras.layers.Add()(
[
x,
inputs
]
)
outputs = tf.keras.layers.Activation(
"relu"
)(x)
model = tf.keras.Model(
inputs=inputs,
outputs=outputs
)
The Functional API makes this architecture straightforward.
๐ง Layer Reuse¶
Functional API allows the same layer to be reused.
For example:
The same layer can process multiple inputs.
This means the layer's weights are shared.
๐ Shared Layer Architecture¶
flowchart TD
INPUT1["Input 1"]
INPUT2["Input 2"]
SHARED["Shared Dense Layer"]
INPUT1 --> SHARED
INPUT2 --> SHARED
SHARED --> OUT1["Output 1"]
SHARED --> OUT2["Output 2"]
This pattern is useful for:
- Siamese networks
- Metric learning
- Shared feature extraction
- Multi-input architectures
๐งช Multiple Inputs¶
Suppose a model receives:
as separate inputs.
flowchart TD
PROFILE["Customer Profile"]
HISTORY["Transaction History"]
PROFILE --> P["Profile Encoder"]
HISTORY --> H["History Encoder"]
P --> MERGE["Concatenate"]
H --> MERGE
MERGE --> OUTPUT["Risk Prediction"]
Functional API implementation:
profile_input = tf.keras.Input(
shape=(20,),
name="profile"
)
history_input = tf.keras.Input(
shape=(50,),
name="history"
)
profile_features = tf.keras.layers.Dense(
64,
activation="relu"
)(profile_input)
history_features = tf.keras.layers.Dense(
128,
activation="relu"
)(history_input)
merged = tf.keras.layers.Concatenate()(
[
profile_features,
history_features
]
)
outputs = tf.keras.layers.Dense(
1,
activation="sigmoid"
)(merged)
model = tf.keras.Model(
inputs=[
profile_input,
history_input
],
outputs=outputs
)
๐ง Multiple Outputs¶
A model can also produce multiple outputs.
For example:
flowchart TD
INPUT["Shared Input"]
BACKBONE["Shared Feature Extractor"]
INPUT --> BACKBONE
BACKBONE --> CLASS["Classification Head"]
BACKBONE --> REG["Regression Head"]
CLASS --> CLASSOUT["Class Output"]
REG --> REGOUT["Regression Output"]
๐งช Multi-Output Model¶
inputs = tf.keras.Input(
shape=(100,)
)
features = tf.keras.layers.Dense(
128,
activation="relu"
)(inputs)
class_output = tf.keras.layers.Dense(
10,
activation="softmax",
name="classification"
)(features)
reg_output = tf.keras.layers.Dense(
1,
name="regression"
)(features)
model = tf.keras.Model(
inputs=inputs,
outputs=[
class_output,
reg_output
]
)
๐ง Multi-Task Learning¶
A multi-output model can support multi-task learning.
For example:
One model can learn:
or:
or:
โ๏ธ Compiling Multi-Output Models¶
Different outputs can have different losses.
model.compile(
optimizer="adam",
loss={
"classification":
"sparse_categorical_crossentropy",
"regression":
"mse"
},
metrics={
"classification":
["accuracy"],
"regression":
["mae"]
}
)
๐ง Loss Weighting¶
Multiple tasks may contribute differently to the total loss.
Conceptually:
[ L_{total} = \lambda_1L_1 + \lambda_2L_2 ]
Example:
model.compile(
optimizer="adam",
loss={
"classification": "sparse_categorical_crossentropy",
"regression": "mse"
},
loss_weights={
"classification": 1.0,
"regression": 0.5
}
)
๐ง Model Composition¶
Keras models can themselves behave like layers.
For example:
encoder = tf.keras.Model(
inputs=encoder_input,
outputs=encoded
)
decoder = tf.keras.Model(
inputs=decoder_input,
outputs=decoded
)
They can then be composed:
This is extremely useful for:
- Autoencoders
- Encoder-decoder architectures
- Transfer Learning
- Reusable model components
๐ Model-as-a-Layer Concept¶
flowchart LR
INPUT["Input"]
ENCODER["Encoder Model"]
DECODER["Decoder Model"]
OUTPUT["Output"]
INPUT --> ENCODER
ENCODER --> DECODER
DECODER --> OUTPUT
๐ง Reusable Model Components¶
Instead of creating one huge model, break it into components:
This improves:
- Reusability
- Testing
- Maintenance
- Experimentation
๐งช Building a Reusable Block¶
def dense_block(
units,
dropout_rate=0.2
):
return tf.keras.Sequential([
tf.keras.layers.Dense(
units,
activation="relu"
),
tf.keras.layers.BatchNormalization(),
tf.keras.layers.Dropout(
dropout_rate
)
])
Use:
๐ง Functional API and CNNs¶
The Functional API becomes particularly valuable for Computer Vision.
For example:
Input Image
โ
Convolution
โ
Pooling
โ
Branch
โโโโโดโโโโ
โ โ
CNN CNN
โโโโโฌโโโโ
โ
Merge
โ
Classifier
This allows architectures beyond simple sequential CNN stacks.
๐ง Functional API and ResNet¶
Residual networks rely heavily on skip connections.
Conceptually:
flowchart TD
INPUT["Input"]
CONV1["Convolution"]
CONV2["Convolution"]
ADD["Add"]
RELU["ReLU"]
INPUT --> CONV1
CONV1 --> CONV2
CONV2 --> ADD
INPUT --> ADD
ADD --> RELU
The Functional API is naturally suited to this type of architecture.
ResNet is covered in detail in:
22. ResNet, Residual Connections and TorchVision
๐ง Functional API and Siamese Networks¶
Siamese networks often process two inputs through shared weights.
flowchart TD
INPUT1["Input A"]
INPUT2["Input B"]
SHARED["Shared Encoder"]
INPUT1 --> SHARED
INPUT2 --> SHARED
SHARED --> EMB1["Embedding A"]
SHARED --> EMB2["Embedding B"]
EMB1 --> DIST["Distance / Similarity"]
EMB2 --> DIST
The Functional API is a natural fit because the same encoder can be reused.
๐ง Functional API and Attention¶
Attention architectures commonly contain:
and multiple computation paths.
Functional graphs can represent such architectures more naturally than simple sequential stacks.
This becomes increasingly important when building:
- Attention models
- Transformers
- Encoder-decoder systems
- Multi-head architectures
๐ง Functional API Model Visualization¶
Keras can visualize the architecture.
For complex architectures, this is extremely useful for verifying:
๐ง Model Summary¶
For a Functional model, the summary can reveal:
This helps identify:
- Unexpected parameter growth
- Shape mismatches
- Incorrect architecture
- Large layers
๐ Inspecting the Graph¶
Functional models expose:
Example:
๐ง Naming Layers¶
Meaningful layer names improve observability.
Instead of:
use:
This becomes especially useful in:
- Debugging
- Model visualization
- Monitoring
- Transfer Learning
- Model inspection
๐ข Production Architecture¶
A production Keras model should ideally have clear boundaries between:
Example:
flowchart LR
INPUT["Input Contract"]
PRE["Preprocessing"]
FEATURES["Feature Extractor"]
HEAD["Prediction Head"]
OUTPUT["Output Contract"]
INPUT --> PRE
PRE --> FEATURES
FEATURES --> HEAD
HEAD --> OUTPUT
๐ง Functional API as Architecture-as-Code¶
The Functional API allows the model topology to be expressed directly in Python.
For example:
inputs = tf.keras.Input(
shape=(128,)
)
x = layer_a(inputs)
x1 = layer_b(x)
x2 = layer_c(x)
merged = tf.keras.layers.Add()(
[x1, x2]
)
outputs = layer_d(
merged
)
model = tf.keras.Model(
inputs,
outputs
)
The code itself reflects the architecture:
Input
โ
Layer A
โ
โโโโโโโโดโโโโโโโ
โ โ
Layer B Layer C
โโโโโโโโฌโโโโโโโ
โ
Add
โ
Layer D
โ
Output
๐ง Sequential โ Functional Migration¶
A Sequential model:
model = tf.keras.Sequential([
tf.keras.Input(
shape=(784,)
),
tf.keras.layers.Dense(
128,
activation="relu"
),
tf.keras.layers.Dense(
10,
activation="softmax"
)
])
can be expressed using Functional API:
inputs = tf.keras.Input(
shape=(784,)
)
x = tf.keras.layers.Dense(
128,
activation="relu"
)(inputs)
outputs = tf.keras.layers.Dense(
10,
activation="softmax"
)(x)
model = tf.keras.Model(
inputs,
outputs
)
The underlying neural network is equivalent.
The difference is the amount of architectural control.
๐ง When Should You Use Sequential?¶
Use Sequential when:
Example:
๐ง When Should You Use Functional API?¶
Use Functional API when you need:
Multiple Inputs
Multiple Outputs
Branches
Merges
Skip Connections
Shared Layers
Complex Graphs
Reusable Components
Examples:
ResNet
Siamese Networks
Multi-Task Models
Encoder-Decoder Models
Complex CNNs
Attention Networks
Transformers
๐ง When Should You Use Model Subclassing?¶
Model subclassing becomes useful when:
- The architecture is highly dynamic
- Forward behavior requires custom control flow
- You need custom training behavior
- The computation graph cannot be conveniently expressed using standard Functional patterns
Example:
class MyModel(
tf.keras.Model
):
def __init__(self):
super().__init__()
self.dense = tf.keras.layers.Dense(
128,
activation="relu"
)
self.output_layer = tf.keras.layers.Dense(
10
)
def call(
self,
inputs
):
x = self.dense(
inputs
)
return self.output_layer(
x
)
Model subclassing is covered further in:
15. Custom Layers, Models and Training Loops
๐งญ Model API Decision Guide¶
flowchart TD
START["Choose Keras Model API"]
START --> SIMPLE{"Simple Linear Stack?"}
SIMPLE -->|Yes| SEQ["Sequential API"]
SIMPLE -->|No| COMPLEX{"Complex Graph?"}
COMPLEX -->|Yes| FUNC["Functional API"]
COMPLEX -->|No| CUSTOM{"Custom Dynamic Behavior?"}
CUSTOM -->|Yes| SUB["Model Subclassing"]
CUSTOM -->|No| FUNC
๐งช Practical Example โ Multi-Input Enterprise Model¶
Imagine a financial risk model receiving:
Architecture:
flowchart TD
PROFILE["Customer Profile"]
TRANS["Transaction Features"]
BEHAVIOR["Behavioral Features"]
PROFILE --> PENC["Profile Encoder"]
TRANS --> TENC["Transaction Encoder"]
BEHAVIOR --> BENC["Behavior Encoder"]
PENC --> MERGE["Feature Fusion"]
TENC --> MERGE
BENC --> MERGE
MERGE --> DENSE["Dense Layers"]
DENSE --> RISK["Risk Score"]
This is an excellent use case for the Functional API.
๐งช Implementation¶
import tensorflow as tf
profile = tf.keras.Input(
shape=(20,),
name="profile"
)
transactions = tf.keras.Input(
shape=(50,),
name="transactions"
)
behavior = tf.keras.Input(
shape=(30,),
name="behavior"
)
profile_features = tf.keras.layers.Dense(
64,
activation="relu",
name="profile_encoder"
)(profile)
transaction_features = tf.keras.layers.Dense(
128,
activation="relu",
name="transaction_encoder"
)(transactions)
behavior_features = tf.keras.layers.Dense(
64,
activation="relu",
name="behavior_encoder"
)(behavior)
features = tf.keras.layers.Concatenate(
name="feature_fusion"
)([
profile_features,
transaction_features,
behavior_features
])
x = tf.keras.layers.Dense(
128,
activation="relu",
name="risk_features"
)(features)
x = tf.keras.layers.Dropout(
0.2,
name="regularization"
)(x)
output = tf.keras.layers.Dense(
1,
activation="sigmoid",
name="risk_score"
)(x)
model = tf.keras.Model(
inputs=[
profile,
transactions,
behavior
],
outputs=output,
name="enterprise_risk_model"
)
๐ง Why This Architecture Is Production-Friendly¶
Each input has a dedicated representation:
These representations are then combined:
This structure makes it easier to:
- Modify individual branches
- Test components
- Reuse encoders
- Monitor inputs
- Extend the architecture
โ Common Mistakes¶
Avoid these mistakes:
- Using Sequential for a graph-based architecture
- Using Functional API when Sequential would be simpler without a reason
- Forgetting that Functional API tensors are symbolic during model construction
- Connecting tensors with incompatible shapes
- Using
Addwhen tensor shapes are incompatible - Confusing
AddwithConcatenate - Accidentally creating separate layers instead of sharing the same layer instance
- Creating unnecessarily complicated model graphs
- Not naming important inputs and outputs
- Ignoring model visualization
- Ignoring parameter counts
- Building giant monolithic Functional models
- Mixing preprocessing logic inconsistently between training and inference
- Forgetting to validate multi-input data contracts
- Using different preprocessing logic for different deployment paths
- Adding branches without a clear modeling reason
๐ง Interview Questions¶
Beginner¶
1. What is the Sequential API?¶
The Sequential API is a Keras model-building approach for creating a simple linear stack of layers.
2. What is the Functional API?¶
The Functional API allows developers to construct arbitrary directed computation graphs by explicitly connecting inputs, layers, and outputs.
3. What is the main difference between Sequential and Functional API?¶
Sequential represents a simple linear stack, while Functional API supports complex graph structures such as branching, merging, multiple inputs, multiple outputs, shared layers, and skip connections.
4. Can Sequential models have multiple inputs?¶
Not naturally. Models with multiple inputs should generally use the Functional API.
5. Can Functional API build simple models?¶
Yes. A simple Sequential model can also be represented using the Functional API.
Intermediate¶
6. What is a symbolic tensor?¶
A symbolic tensor represents a node or intermediate value in the Keras computation graph rather than an actual batch of numerical data during model construction.
7. What is a skip connection?¶
A skip connection allows information to bypass one or more layers and later be combined with the transformed representation.
8. Why is the Functional API useful for ResNet?¶
ResNet uses residual/skip connections, which require graph structures that are not naturally represented by a simple sequential stack.
9. What is layer sharing?¶
Layer sharing means using the same layer instance, and therefore the same learned weights, on multiple inputs or paths.
10. What is a multi-input model?¶
A model that receives more than one independent input tensor.
11. What is a multi-output model?¶
A model that produces multiple outputs, potentially representing different tasks.
12. What is multi-task learning?¶
Multi-task learning trains a shared representation to solve multiple related tasks, often using separate task-specific output heads.
Advanced¶
13. Why would you use the Functional API instead of subclassing?¶
When the architecture can be clearly expressed as a computation graph, the Functional API provides strong graph visibility, model inspection, visualization, and serialization while remaining flexible.
14. Why might model subclassing be necessary?¶
Highly dynamic computation, custom control flow, or specialized training behavior may be easier to implement using subclassing.
15. What is the difference between Add and Concatenate?¶
Add performs element-wise addition and requires compatible shapes. Concatenate joins tensors along a specified dimension and generally increases the feature dimension.
16. How does layer sharing work?¶
The same layer object is applied to multiple inputs:
Both paths use the same learned weights.
17. How would you design a multi-input enterprise model?¶
Separate each input into an appropriate encoder, transform each representation, fuse the representations, and pass the fused representation into shared prediction layers.
18. Why is model visualization important?¶
It helps verify:
and can expose architectural mistakes before training becomes expensive.
๐งช Practical Exercises¶
Exercise 1 โ Sequential Classifier¶
Build:
using Sequential.
Exercise 2 โ Convert Sequential to Functional¶
Implement the same architecture using the Functional API.
Compare:
Exercise 3 โ Branching Network¶
Create:
Exercise 4 โ Skip Connection¶
Implement:
Input
โ
โโโโโโโโโโโโโโโโโ
โ โ
Dense โ
โ โ
Dense โ
โ โ
โโโโโ Add โโโโโโโ
โ
Output
Exercise 5 โ Multi-Input Model¶
Build a model accepting:
Create separate encoders and combine them using Concatenate.
Exercise 6 โ Multi-Output Model¶
Create one shared network with:
Train it using different losses for each output.
Exercise 7 โ Shared Encoder¶
Build a Siamese-style architecture:
Produce two embeddings and calculate a similarity score.
๐ Key Takeaways¶
- Keras provides multiple model-construction approaches.
- Sequential is ideal for simple linear stacks.
- Functional API is designed for arbitrary computation graphs.
- Functional API supports multiple inputs and outputs.
- Functional API supports branching and merging.
- Functional API supports shared layers.
- Skip connections are naturally implemented using Functional API.
- Residual networks rely heavily on this capability.
- Functional API uses symbolic tensors during model construction.
tf.keras.Model(inputs, outputs)creates a Functional model.Addperforms element-wise addition.Concatenatejoins tensors along a dimension.- Multi-output models can support multi-task learning.
- Different outputs can use different losses and metrics.
- Loss weights can balance multiple tasks.
- Keras models can be composed and reused as layers.
- Meaningful layer names improve model inspection and maintainability.
- Model visualization is especially valuable for complex architectures.
- Sequential should not be forced onto architectures that require graph connectivity.
- Functional API is often the right abstraction for production-grade complex neural networks.
- Model subclassing is useful when computation or behavior requires greater customization.
- Good architecture design should balance flexibility, readability, maintainability, and operational requirements.
๐ Further Reading¶
Continue with:
- 15. Custom Layers, Models and Training Loops
- 16. PyTorch Fundamentals and Tensors
- 18. Building Classification and Regression Models
- 19. Convolutional Neural Networks
- 20. CNN Architecture, Optimization and Training
- 22. ResNet, Residual Connections and TorchVision
- 26. Attention and Positional Encoding
- 27. Transformer Architecture
The next chapter moves from standard Keras model construction into custom layers, custom models, and custom training loops, giving you much deeper control over the training process.
โก๏ธ Next Chapter¶
15. Custom Layers, Models and Training Loops
Enterprise AI Engineering Handbook
Building Production-Grade Enterprise AI Systems โ One Chapter at a Time.