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.
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:
- '
keraswas backend-agnostic' - '
tf.keraswas TensorFlow-only' - '
tf.kerasfit better with TensorFlow internals' - standalone
kerasoften 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:
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:
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
Kerasif you explicitly wanted multi-backend portability - choose
tf.kerasif 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
Keraswas an independent high-level library with multi-backend support. - '
tf.keraswas 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
Kerasoften had portability advantages, whiletf.kerasreduced TensorFlow session and graph friction. - Do not mix
kerasandtf.kerasimports casually in the same project.
Related reading
- What is the difference between Keras model.evaluate and model.predict?
- What is the difference between loss function and metric in Keras?
- What is the difference between MaxPool and MaxPooling layers in Keras?
- What is the difference between MaxPool and MaxPooling layers in Keras?
- What is the difference between keras.tokenize.text_to_sequences and word embeddings
- What is the difference between model.fit an model.evaluate in Keras?
- What is the difference between labeled and unlabeled data?
- What is the difference between LDA and NTM in Amazon Sagemaker for Topic Modeling?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.