TensorFlow
Keras
tf.keras
deep learning
machine learning

What is the difference between Keras and tf.keras in TensorFlow 1.1?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

In the TensorFlow 1.x era, Keras and tf.keras looked similar on the surface but were not the same product. Standalone Keras was an independent high-level library that could target multiple backends, while tf.keras was TensorFlow's in-tree Keras implementation with tighter graph and session integration.

The Core Difference

Standalone Keras was installed as its own package and historically supported backends such as TensorFlow, Theano, and CNTK. The design goal was portability: write the model once and switch the backend.

tf.keras lived inside TensorFlow. In TensorFlow 1.1 specifically, that integration story mattered more than feature completeness. The benefit was that you stayed inside the TensorFlow ecosystem for sessions, variables, graph collections, summaries, checkpoints, and TensorFlow-specific tooling.

At a high level:

  • 'keras was backend-agnostic'
  • 'tf.keras was TensorFlow-only'
  • 'tf.keras fit better with TensorFlow internals'
  • standalone keras often moved on a different release schedule

Why This Mattered In TensorFlow 1.x

TensorFlow 1.x used explicit graphs and sessions. That made library boundaries more visible than they are in newer eager-first APIs.

If you built a model with standalone Keras, you often had to think about how it connected to the TensorFlow session, how callbacks interacted with TensorBoard, and how model saving fit into the larger TensorFlow workflow.

With tf.keras, those seams were smaller because the API belonged to TensorFlow itself. That usually meant:

  • easier use of TensorFlow ops around the model
  • cleaner integration with TensorBoard and checkpoints
  • fewer surprises with session ownership
  • better alignment with TensorFlow data pipelines

In the TensorFlow 1.1 timeframe, however, many developers still preferred standalone Keras because it was more mature and more widely documented.

Example: Standalone Keras

This is the classic standalone style:

python
1from keras.models import Sequential
2from keras.layers import Dense
3
4model = Sequential([
5    Dense(16, activation="relu", input_shape=(4,)),
6    Dense(3, activation="softmax")
7])
8
9model.compile(
10    optimizer="adam",
11    loss="categorical_crossentropy",
12    metrics=["accuracy"]
13)

The code is concise, but the package is separate from TensorFlow. Historically, that meant the backend selection and parts of the execution environment lived outside the TensorFlow package boundary.

Example: tf.keras

This version uses the TensorFlow namespace:

python
1import tensorflow as tf
2
3model = tf.keras.Sequential([
4    tf.keras.layers.Dense(16, activation="relu", input_shape=(4,)),
5    tf.keras.layers.Dense(3, activation="softmax")
6])
7
8model.compile(
9    optimizer="adam",
10    loss="categorical_crossentropy",
11    metrics=["accuracy"]
12)

The model-building experience is intentionally similar. The real difference is operational: the layers, variables, optimizers, and serialization behavior are managed by TensorFlow's own implementation.

Practical Tradeoffs

If you were writing code specifically for TensorFlow 1.x, tf.keras reduced friction. You did not need to bridge between an external Keras package and TensorFlow as often.

If you cared about backend portability, standalone Keras was more aligned with that goal.

Another practical difference was release cadence. A standalone package could add features on its own schedule. By contrast, tf.keras features depended on TensorFlow releases. In early TensorFlow 1.x, that sometimes meant the two were close in API style but not perfectly equivalent in behavior or availability.

Model saving was another area where integration mattered. Using TensorFlow-managed checkpoints and graph infrastructure was generally simpler when the model already lived in tf.keras.

What To Prefer

In historical TensorFlow 1.x projects, the answer depended on context:

  • choose standalone Keras if you explicitly wanted multi-backend portability
  • choose tf.keras if the rest of your stack was already deeply TensorFlow-specific

In practice, many teams eventually standardized on tf.keras because TensorFlow kept moving toward first-party Keras integration.

Common Pitfalls

A common mistake is assuming keras and tf.keras were always interchangeable in TensorFlow 1.x. They often looked similar, but mixing imports in the same model could produce subtle bugs around layers, serialization, and optimizer state.

Another issue is applying modern TensorFlow assumptions to early TensorFlow 1.1 code. In that period, tf.keras was not yet the universally obvious default it later became.

Developers also ran into confusion around sessions and graphs. In TensorFlow 1.x, those execution details mattered. First-party integration was one of the main reasons to prefer tf.keras in TensorFlow-heavy code.

Finally, avoid mixing the two namespaces in one code path. Pick one implementation boundary for a project and stay consistent.

Summary

  • Standalone Keras was an independent high-level library with multi-backend support.
  • 'tf.keras was TensorFlow's built-in Keras implementation and integrated more naturally with TensorFlow 1.x internals.'
  • In TensorFlow 1.1, the biggest difference was ecosystem integration, not model syntax.
  • Standalone Keras often had portability advantages, while tf.keras reduced TensorFlow session and graph friction.
  • Do not mix keras and tf.keras imports casually in the same project.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.