×
1 Choose EITC/EITCA Certificates
2 Learn and take online exams
3 Get your IT skills certified

Confirm your IT skills and competencies under the European IT Certification framework from anywhere in the world fully online.

EITCA Academy

Digital skills attestation standard by the European IT Certification Institute aiming to support Digital Society development

LOG IN TO YOUR ACCOUNT

CREATE AN ACCOUNT FORGOT YOUR PASSWORD?

FORGOT YOUR PASSWORD?

AAH, WAIT, I REMEMBER NOW!

CREATE AN ACCOUNT

ALREADY HAVE AN ACCOUNT?
EUROPEAN INFORMATION TECHNOLOGIES CERTIFICATION ACADEMY - ATTESTING YOUR PROFESSIONAL DIGITAL SKILLS
  • SIGN UP
  • LOGIN
  • INFO

EITCA Academy

EITCA Academy

The European Information Technologies Certification Institute - EITCI ASBL

Certification Provider

EITCI Institute ASBL

Brussels, European Union

Governing European IT Certification (EITC) framework in support of the IT professionalism and Digital Society

  • CERTIFICATES
    • EITCA ACADEMIES
      • EITCA ACADEMIES CATALOGUE<
      • EITCA/CG COMPUTER GRAPHICS
      • EITCA/IS INFORMATION SECURITY
      • EITCA/BI BUSINESS INFORMATION
      • EITCA/KC KEY COMPETENCIES
      • EITCA/EG E-GOVERNMENT
      • EITCA/WD WEB DEVELOPMENT
      • EITCA/AI ARTIFICIAL INTELLIGENCE
    • EITC CERTIFICATES
      • EITC CERTIFICATES CATALOGUE<
      • COMPUTER GRAPHICS CERTIFICATES
      • WEB DESIGN CERTIFICATES
      • 3D DESIGN CERTIFICATES
      • OFFICE IT CERTIFICATES
      • BITCOIN BLOCKCHAIN CERTIFICATE
      • WORDPRESS CERTIFICATE
      • CLOUD PLATFORM CERTIFICATENEW
    • EITC CERTIFICATES
      • INTERNET CERTIFICATES
      • CRYPTOGRAPHY CERTIFICATES
      • BUSINESS IT CERTIFICATES
      • TELEWORK CERTIFICATES
      • PROGRAMMING CERTIFICATES
      • DIGITAL PORTRAIT CERTIFICATE
      • WEB DEVELOPMENT CERTIFICATES
      • DEEP LEARNING CERTIFICATESNEW
    • CERTIFICATES FOR
      • EU PUBLIC ADMINISTRATION
      • TEACHERS AND EDUCATORS
      • IT SECURITY PROFESSIONALS
      • GRAPHICS DESIGNERS & ARTISTS
      • BUSINESSMEN AND MANAGERS
      • BLOCKCHAIN DEVELOPERS
      • WEB DEVELOPERS
      • CLOUD AI EXPERTSNEW
  • FEATURED
  • SUBSIDY
  • HOW IT WORKS
  •   IT ID
  • ABOUT
  • CONTACT
  • MY ORDER
    Your current order is empty.
EITCIINSTITUTE
CERTIFIED

Is it possible to convert a model from json format back to h5?

by Michał Otoka / Thursday, 11 September 2025 / Published in Artificial Intelligence, EITC/AI/GCML Google Cloud Machine Learning, Advancing in Machine Learning, Importing Keras model into TensorFlow.js

The process of converting models between different serialization formats is a common requirement in the field of deep learning, particularly when moving between environments or frameworks, such as from Keras (using HDF5 files, `.h5`) to TensorFlow.js (using JSON), and vice versa. The specific question of whether it is possible to convert a model from the TensorFlow.js JSON format back to the Keras HDF5 (`.h5`) format involves consideration of several technical aspects, including what information is present in each format, the available tooling, and potential limitations in the conversion process.

Understanding the Model Formats

1. Keras HDF5 (`.h5`) Format:
– This is the standard serialization format used by Keras for saving entire models, including the model architecture, weights, training configuration (e.g., optimizer, loss, metrics), and the state of the optimizer.
– The HDF5 format is binary and well-supported in Python-based environments.

2. TensorFlow.js JSON Format:
– TensorFlow.js saves models using a JSON file for the model topology (architecture) and one or more binary `.bin` files for the weights.
– The JSON format is text-based, designed for use in web browsers with JavaScript, and generally omits Python-specific configuration, such as certain custom layers or advanced serialization features.

Conversion Workflow

The typical workflow involves converting a Keras model to the TensorFlow.js format for deployment in web environments:

– Keras `.h5` → TensorFlow.js (JSON + weights `.bin`)
Using the `tensorflowjs_converter` command-line tool.

The reverse process—converting from TensorFlow.js's JSON format back to a Keras `.h5` file—may be required if, for instance, a model has been updated or fine-tuned in the browser, and you want to further work with it in Python, or archive the updated model in a server environment.

Is Reverse Conversion Possible?

Yes, it is possible to convert a model from TensorFlow.js's JSON (with weights in `.bin` files) back to the Keras HDF5 (`.h5`) format, although there are specific considerations and requirements:

1. Tool Support:
– The TensorFlow.js library provides a Python module, `tensorflowjs`, that includes functionality for loading TensorFlow.js models and converting them back to Keras format. This is not as prominently documented as the Keras-to-TFJS workflow but is available.
– The function `tensorflowjs.converters.load_keras_model` can be used to load a TensorFlow.js model into Python as a Keras model, after which it can be saved as a `.h5` file.

2. Requirements:
– The original model must have been converted from Keras (or TensorFlow SavedModel) to TensorFlow.js format using supported tools. Custom layers, ops, or certain Python-specific configuration might not be preserved or may require additional handling.
– The JSON topology and weights `.bin` files must be present and accessible.

3. Limitations:
– Any custom layers or functions used in the original Keras model must be provided when loading the model; otherwise, the loading process will fail.
– Some optimizer state or configuration may be lost in the conversion, particularly if the model was trained or modified in the browser using TensorFlow.js. The conversion process focuses on model architecture and weights.
– There may be incompatibilities if the TensorFlow.js model was created or modified in ways not directly supported by Keras.

Practical Example:

Assume you have a TensorFlow.js model directory with the following files:
– `model.json` (model topology and weight manifest)
– `group1-shard1of1.bin` (weight binary file)

To convert this model back to Keras `.h5`, follow these steps:

1. Install the Required Package:

bash
   pip install tensorflowjs
   

2. Load the Model in Python:

python
   from tensorflowjs.converters import load_keras_model

   # Path to the directory containing model.json and .bin files
   tfjs_model_dir = './tfjs_model_dir'

   # Load the model
   model = load_keras_model(tfjs_model_dir)
   

3. Save the Model as `.h5`:

python
   model.save('restored_model.h5')
   

This process reconstructs the Keras model in memory and allows you to save it in the HDF5 format. The restored `.h5` file will contain the model architecture and weights. However, training configuration (optimizer state, compiled loss, and metrics) may need to be re-specified if you plan to continue training.

Special Considerations:

– Custom Layers:
If your model uses custom layers or objects, you need to provide them when loading the model, both in the conversion to TensorFlow.js and back. For instance:

python
  custom_objects = {'MyCustomLayer': MyCustomLayer}
  model = load_keras_model(tfjs_model_dir, custom_objects=custom_objects)
  

– Model Compatibility:
Ensure that the model was originally compatible with Keras serialization. Models created entirely in TensorFlow.js without reference to Python/Keras may use ops or features not present in Keras, resulting in conversion errors or incomplete models.

– Version Compatibility:
Differences in versioning between TensorFlow.js converters and Keras may lead to incompatibility. It is advisable to use matched versions or test the conversion pipeline for your particular use case.

– Training State:
The conversion will preserve the architecture and weights but may not preserve the training state (e.g., optimizer configuration, epoch, batch size). If you need to resume training, you should recompile the model in Keras with the appropriate optimizer, loss, and metrics.

Alternative Approach: Manual Reconstruction

In scenarios where automatic conversion fails due to incompatibility or missing features, one can manually reconstruct the model:

1. Parse the `model.json` file to understand the architecture.
2. Manually define the architecture in Keras.
3. Load the weights from the binary `.bin` files into the Keras model using the appropriate APIs.

While this method is more labor-intensive, it can be necessary for highly customized models or when using unsupported layers.

References and Documentation

– [TensorFlow.js Converter Documentation](https://www.tensorflow.org/js/tutorials/conversion/import_keras)
– [Keras Model Serialization](https://keras.io/guides/serialization_and_saving/)
– [TensorFlow.js GitHub Issues](https://github.com/tensorflow/tfjs)

Converting models from TensorFlow.js's JSON format back to Keras's HDF5 format is supported and feasible, provided the model was originally exported from a compatible Keras model and has not been fundamentally altered in ways incompatible with Keras. The process requires the TensorFlow.js Python API, careful handling of custom layers, and awareness of possible loss in training configuration. Manual reconstruction is a viable alternative when automated tools cannot handle particular customizations.

Other recent questions and answers regarding Importing Keras model into TensorFlow.js:

  • Can someone without experience in Python and with basic notions of AI use TensorFlow.js to load a model converted from Keras, interpret the model.json file and shards, and ensure interactive real-time predictions in the browser?
  • What are the limitations of using client-side models in TensorFlow.js?
  • What is the final step in the process of importing a Keras model into TensorFlow.js?
  • What is the significance of the additional shard files (`group1-shard1of1`, `group2-shard1of1`, and `group3-shard1of1`) in the `tfjs_files` folder?
  • What is the role of the `model.json` file in the TensorFlow.js model folder?
  • What is the purpose of the TensorFlow.js converter in the context of importing a Keras model into TensorFlow.js?

More questions and answers:

  • Field: Artificial Intelligence
  • Programme: EITC/AI/GCML Google Cloud Machine Learning (go to the certification programme)
  • Lesson: Advancing in Machine Learning (go to related lesson)
  • Topic: Importing Keras model into TensorFlow.js (go to related topic)
Tagged under: Artificial Intelligence, Deep Learning, HDF5, Keras, Model Conversion, TensorFlow.js
Home » Artificial Intelligence » EITC/AI/GCML Google Cloud Machine Learning » Advancing in Machine Learning » Importing Keras model into TensorFlow.js » » Is it possible to convert a model from json format back to h5?

Certification Center

USER MENU

  • My Account

CERTIFICATE CATEGORY

  • EITC Certification (117)
  • EITCA Certification (9)

What are you looking for?

  • Introduction
  • How it works?
  • EITCA Academies
  • EITCI DSJC Subsidy
  • Full EITC catalogue
  • Your order
  • Featured
  •   IT ID
  • EITCA reviews (Medium publ.)
  • About
  • Contact

EITCA Academy is a part of the European IT Certification framework

The European IT Certification framework has been established in 2008 as a Europe based and vendor independent standard in widely accessible online certification of digital skills and competencies in many areas of professional digital specializations. The EITC framework is governed by the European IT Certification Institute (EITCI), a non-profit certification authority supporting information society growth and bridging the digital skills gap in the EU.
Eligibility for EITCA Academy 90% EITCI DSJC Subsidy support
90% of EITCA Academy fees subsidized in enrolment

    EITCA Academy Secretary Office

    European IT Certification Institute ASBL
    Brussels, Belgium, European Union

    EITC / EITCA Certification Framework Operator
    Governing European IT Certification Standard
    Access contact form or call +32 25887351

    Follow EITCI on X
    Visit EITCA Academy on Facebook
    Engage with EITCA Academy on LinkedIn
    Check out EITCI and EITCA videos on YouTube

    Funded by the European Union

    Funded by the European Regional Development Fund (ERDF) and the European Social Fund (ESF) in series of projects since 2007, currently governed by the European IT Certification Institute (EITCI) since 2008

    Information Security Policy | DSRRM and GDPR Policy | Data Protection Policy | Record of Processing Activities | HSE Policy | Anti-Corruption Policy | Modern Slavery Policy

    Automatically translate to your language

    Terms and Conditions | Privacy Policy
    EITCA Academy
    • EITCA Academy on social media
    EITCA Academy


    © 2008-2026  European IT Certification Institute
    Brussels, Belgium, European Union

    TOP

    We care about your privacy

    EITCI uses cookies and similar technologies to keep this site secure, remember your choices, provide personalized experience, measure the traffic, serve more relevant content and certification programmes. You can accept all cookies or customize your preferences. Cookies are variables used to store website specific information on your device to facilitate processing of data for personalized website visit, such as login to your account, accessing the programmes, placing enrolment orders in chosen programmes and improving your EITC certification journey. You can change or withdraw your consent at any time by clicking the Consent Preferences button at the left-bottom of your screen. We respect your choices and are committed to providing you with a transparent and secure browsing experience, which may be limited when cookies aren't accepted. For more details refer to the Privacy Policy
    Customize Consent Preferences
    We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.
    The cookies categorized as Necessary are stored on your browser as they are essential for enabling the basic functionalities of the site.
    To learn more about how Google processes personal information, visit: Google privacy policy

    Necessary

    Always Active

    Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

    Functional

    Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

    Preferences

    Stores personalization choices such as interface preferences.

    External media and social features

    Allows embedded video, social, chat, and external interactive services that may set their own cookies. Keep off until the user chooses these features.

    Analytics

    Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

    Marketing and conversions

    Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

    CHAT WITH SUPPORT
    Do you have any questions?
    Attach files with the paperclip or paste screenshots into the message box (Ctrl+V). Max 5 file(s), 10 MB each.
    We will reply here and by email. Your conversation is tracked with a support token.