Introduction to Keras & TensorFlow
Keras Basics
3 min read
Published Nov 17 2025
Guide Sections
Guide Comments
Keras is a high-level deep learning API designed to make building neural networks:
- Simple
- Fast
- Modular
- Consistent
- Readable
Originally, Keras was a standalone library that could run on top of multiple backends. Today, Keras is built directly into TensorFlow, and the official version is:
This means you use:
- TensorFlow for computation
- Keras as the high-level interface
- Both integrated into one workflow
Keras handles:
- Layers
- Models
- Training
- Losses / metrics
- Preprocessing
- Utilities
- Data pipelines
- Transfer learning
TensorFlow handles the heavy lifting:
- GPU acceleration
- Automatic differentiation
- Graph optimisation
- Large-scale data pipelines
Why Keras Exists
Deep learning can be complicated. Keras solves this by providing:
- A clean, Pythonic API - Keras code is readable, short, and structured.
- Sensible defaults - You rarely need low-level details unless you choose to.
- Modular building blocks - Models are assembled from layers exactly like building with Lego bricks.
- Interoperability with TensorFlow - You can drop down to low-level TF code whenever needed.
- Fast prototyping - You can create, compile, and train a model in under 10 lines.
Keras is especially helpful when you want to focus on ideas rather than the mechanics of neural network training.
What Keras Is Good At
Keras is well suited for building models in:
- Image classification (CNNs)
- Natural language processing (LSTM, GRU, Transformers)
- Tabular deep learning
- Time-series forecasting
- Reinforcement learning (with wrappers)
- Transfer learning & fine-tuning
- Autoencoders
- GANs (generative models)
Keras makes these workflows accessible and beginner-friendly, while still being powerful enough for production.
What Keras Is Not Ideal For
Keras is not the best choice for:
- Extremely large-scale distributed training (use low-level TF or JAX)
- Highly experimental architectures requiring custom training loops (although possible in TF)
- Classical ML tasks like SVMs, decision trees, boosting (use Scikit-learn)
How Keras Fits Into the TensorFlow Ecosystem
TensorFlow provides:
- Tensors
- Automatic differentiation
- Device placement (CPU / GPU / TPU)
- Training loops (tf.GradientTape)
- Data loading (tf.data)
Keras provides:
- High-level model classes (
Sequential,Model) - High-level layers
- Fit/evaluate/predict loops
- Callbacks (EarlyStopping, Checkpointing)
- Preprocessing utilities
- Dataset helpers (e.g.,
keras.datasets)
They work together seamlessly.
The Two Ways to Build Models in Keras
There are two major Keras model-building styles:
1) Sequential API
Best for simple, feed-forward architectures
Example:
Easy, readable, limited flexibility.
2) Functional API
Best for flexible or multi-input/multi-output models
Example:
Needed for:
- Skip connections
- Multiple inputs
- Multiple outputs
- Custom topologies
Most real-world models use this.
The Core Keras Workflow
Deep learning with Keras always follows the same pattern:
- Load and prepare data
- Build the model
- Compile the model (loss, optimiser, metrics)
- Train the model (fit)
- Evaluate the model
- Use the model (predict)
- Save / load the model
Installing Keras
This installs:
- TensorFlow
- Keras
- GPU support if available on your system
- All basic dependencies
Importing Keras
All imports follow this pattern:
Example: Minimal Keras Program (Full Workflow)
We’ll build something simple just to show the shape of a Keras script.
This short code sample illustrates the entire workflow. We will revisit each part in depth in later sections.














