code: def initialise_from_mid_fusion(
      params: PyTree,
      restored_params: PyTree,
      config: ml_collections.ConfigDict,
      restored_model_cfg: ml_collections.ConfigDict,
  ) -> PyTree:
      """Initialise MBT from "separate_encoders_and_concat" pretrained models.
  
      Here, we convert the model parameter names to the same format as
      "separate_encoders" by replicating the model parameters from the shared part
      to each of the individual encoders.
      And then, we initialise the way we would for a "separate_encoders" model.
  
      Args:
       params: PyTree of model parameters in the target model.
       restored_params: PyTree of model parameters to restore.
       config: Configuration of the target model.
       restored_model_cfg: Configuration of the restored model.
  
      Returns:
        Adapted parameters for MBT.
      """
      if (
          restored_model_cfg.model.encoder_strategy
          != "separate_encoders_and_concat"
      ):
          raise AssertionError(
              'Only support "separate_encoders_and_concat" models.'
          )
  
      flattened_restored = _flatten(restored_params)
  
      ## Duplicate the shared parameters to each encoder.
      # First, we need to determine the number of layers
      num_separate_layers = 0
      num_shared_layers = 0
      for name in flattened_restored:
          for modality in restored_model_cfg.masked_feature_loss.target:
              match = re.match(
                  f"Transformer_{modality}/encoderblock_([0-9]+)", name
              )
              if match:
                  layer_id = int(match[1]) + 1
                  num_separate_layers = max(
                      num_separate_layers, layer_id
                  )
  
          # Now, the number of shared layers
          match = re.match(
              "Transformer_concat/encoderblock_([0-9]+)", name
          )
          if match:
              layer_id = int(match[1]) + 1
              num_shared_layers = max(num_shared_layers, layer_id)
  
      if num_shared_layers == 0 or num_separate_layers == 0:
          raise AssertionError(
              "num_shared_layers and num_separate_layers should both be > 0."
              f"Got {num_shared_layers} and {num_separate_layers}"
          )
  
      # Now, we rename the shared layers.
      flattened_restored_renamed = {}
      for name, value in flattened_restored.items():
          if "Transformer_concat/" in name:
              if "Transformer_concat/encoder_norm" in name:
                  new_name = name.replace(
                      "Transformer_concat/", "Transformer/"
                  )
                  flattened_restored_renamed[new_name] = value
                  continue
  
              layer_id = int(
                  re.match(
                      "Transformer_concat/encoderblock_([0-9]+)", name
                  )[1]
              )
              new_id = layer_id + num_separate_layers
              name_rgb = name.replace(
                  "Transformer_concat", "Transformer_rgb"
              )
              name_rgb = name_rgb.replace(
                  f"encoderblock_{layer_id}", f"encoderblock_{new_id}"
              )
              flattened_restored_renamed[name_rgb] = value
  
              name_spec = name.replace(
                  "Transformer_concat", "Transformer_spectrogram"
              )
              name_spec = name_spec.replace(
                  f"encoderblock_{layer_id}", f"encoderblock_{new_id}"
              )
              flattened_restored_renamed[name_spec] = value
          else:
              flattened_restored_renamed[name] = value
  
      restored_params = _unflatten(flattened_restored_renamed)
      logging.info("Restored parameters after renaming:")
      debug_utils.log_param_shapes(restored_params)
      return initialise_from_separate_encoders(
          params, restored_params, config, restored_model_cfg
      )
  
imports: import functools
  import re
  from typing import Any, Callable, Dict, Optional, Sequence, Tuple
  from absl import logging
  import flax
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.common_lib import debug_utils
  from scenic.model_lib.base_models import base_model
  from scenic.model_lib.base_models import classification_model
  from scenic.model_lib.base_models import model_utils
  from scenic.model_lib.base_models.classification_model import ClassificationModel
  from scenic.model_lib.layers import nn_layers
  from scenic.projects.av_mae import model_utils
  from scenic.projects.baselines import vit
  from scenic.projects.mbt import model
  from scenic.projects.vivit import model_utils
  import scipy
label_desc: Use image node_id 9 for calling a global function with example usage: initialise_from_mid_fusion(params, restored_params, config, restored_model_cfg) and returns: initialise_from_separate_encoders