CS5720 - Week 9
Slide 169 of 180

Keras Functional API

What is the Functional API?

The Keras Functional API is a more flexible way to build models compared to the Sequential API. It allows you to create complex architectures with multiple inputs, outputs, and non-linear topologies.
Why use Functional API?

Complex architectures - Multi-input/output models
Shared layers - Reuse layers across different paths
Non-linear topologies - Skip connections, branches
Model subclassing - Custom training loops
💡 Key Insight:
Think of Sequential as a simple chain, and Functional API as a flexible graph where layers can connect in any way!

Sequential vs Functional

  • 🔗 Simplicity
    Sequential: Simple linear stack vs Functional: Flexible graph
  • 🌊 Flexibility
    Sequential: One input/output vs Functional: Multiple I/O
  • 🏗️ Architecture
    Sequential: Linear only vs Functional: Any topology
  • 🔄 Layer Sharing
    Sequential: No sharing vs Functional: Full sharing
🎯 When to Use Each:
Sequential: Simple feedforward networks
Functional: ResNet, Inception, multi-task learning

Building Models with Functional API

🏗️
Basic Model
Simple input → hidden → output with functional syntax
🔀
Multi-Input Model
Multiple inputs merged into single prediction
🔄
Shared Layers
Reuse layers across different branches
Click any model type above to see detailed implementation examples!
Prepared by Dr. Gorkem Kar