code: def update_model(params: dict, path: str):
      logger.info(f"Updating model at {path}")
      trainer_params = TrainerParams.from_dict(params)
      post_init(trainer_params)
      scenario_params = trainer_params.scenario
      scenario = CalamariScenario(scenario_params)
      inputs = scenario.data.create_input_layers()
      outputs = scenario.graph.predict(inputs)
      pred_model = keras.models.Model(inputs, outputs)
      with h5py.File(path + ".h5", "r") as f:
          if "layer_names" not in f.attrs and "model_weights" in f:
              f = f["model_weights"]
          graph = pred_model.layers[3]._layers[0]
          load_weights_from_hdf5_group(
              f,
              [l for l in graph.layer_instances if len(l.weights) > 0]
              + [graph.logits],
          )
  
      logger.info(f"Writing converted model at {path}.tmp.h5")
      pred_model.save(path + ".tmp.h5", include_optimizer=False)
      logger.info(
          f"Attempting to load converted model at {path}.tmp.h5"
      )
      keras.models.load_model(
          path + ".tmp.h5",
          custom_objects=CalamariScenario.model_cls().all_custom_objects(),
      )
      logger.info(f"Replacing old model at {path}.h5")
      os.remove(path + ".h5")
      os.rename(path + ".tmp.h5", path + ".h5")
      logger.info(f"New model successfully written")
      keras.backend.clear_session()
  
imports: import inspect
  import os
  from typing import Optional
  import logging
  import h5py
  from tensorflow import keras
  from tensorflow.python.keras.saving.hdf5_format import load_weights_from_hdf5_group
  from tfaip.util.tfaipargparse import post_init
  from calamari_ocr.ocr.savedmodel.migrations.version3_4to5 import migrate3to5
  from calamari_ocr.ocr.scenario import CalamariScenario
  from calamari_ocr.ocr.training.params import TrainerParams
label_desc: Use image node_id 1 for calling a global function with example usage: update_model(params, path) without return types