code: def initialise_from_separate_encoders(
      params: PyTree,
      restored_params: PyTree,
      config: ml_collections.ConfigDict,
      restored_model_cfg: ml_collections.ConfigDict,
  ) -> PyTree:
      """Initialise MBT parameters from MultiMAE with separate encoders.
  
      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.
      """
  
      del restored_model_cfg  # Can be used for asserts.
  
      flattened_params = _flatten(params)
      flattened_restored = _flatten(restored_params)
  
      # We need to check if we are restoring RGB only, Spectogram only or
      # RGB and Spectogram
      restore_rgb_spec = False
      restore_rgb_only = False
      restore_spec_only = False
  
      if len(config.model.modality_fusion) > 2:
          raise AssertionError("Only support 1 or 2 modalities.")
      if len(config.model.modality_fusion) == 2:
          if config.model.modality_fusion[0] != "rgb":
              raise AssertionError(
                  "We assume that rgb is the first listed modality."
              )
          restore_rgb_spec = True
      elif config.model.modality_fusion[0] == "spectrogram":
          restore_spec_only = True
      elif config.model.modality_fusion[0] == "rgb":
          restore_rgb_only = True
      else:
          raise AssertionError(
              f"Unknown modalities {config.model.modality_fusion}"
          )
  
      # Use a regex to rename all the transformer variables.
      renamed_params = {}
      for name, value in flattened_restored.items():
          new_name = name
          if restore_rgb_spec or restore_rgb_only:
              new_name = re.sub(
                  "Transformer_rgb/encoderblock_([0-9]+)",
                  r"Transformer/encoderblock_\1",
                  new_name,
              )
          if restore_rgb_spec:
              new_name = re.sub(
                  "Transformer_spectrogram/encoderblock_([0-9]+)",
                  r"Transformer/encoderblock_\1_spec",
                  new_name,
              )
          if restore_spec_only:
              new_name = re.sub(
                  "Transformer_spectrogram/encoderblock_([0-9]+)",
                  r"Transformer/encoderblock_\1",
                  new_name,
              )
  
          renamed_params[new_name] = value
  
      # Now handle special cases.
      renamed_params["embedding/bias"] = renamed_params.pop(
          "embedding_rgb/bias"
      )
      renamed_params["embedding/kernel"] = renamed_params.pop(
          "embedding_rgb/kernel"
      )
      renamed_params["embedding_spec/bias"] = renamed_params.pop(
          "embedding_spectrogram/bias"
      )
      renamed_params["embedding_spec/kernel"] = renamed_params.pop(
          "embedding_spectrogram/kernel"
      )
  
      if (
          "embedding_spec/kernel" in flattened_params
          and flattened_params["embedding_spec/kernel"].shape[2] == 3
          and renamed_params["embedding_spec/kernel"].shape[2] == 1
      ):
          value = renamed_params["embedding_spec/kernel"]
          value = np.tile(value, [1, 1, 3, 1])
          renamed_params["embedding_spec/kernel"] = value
      else:
          logging.info("Not inflating spectrogram embedding filter.")
  
      # Note: MAE has separate layer-norms per modality:
      # ie Transformer_rgb/encoder_norm/... and
      # Transformer_spectogram/encoder_norm/...
      # MBT has a single layer-norm. We do not rename any of the MAE layer-norms
      # and keep the standard identity initialisation here.
  
      # Assign transformed names.
      for name in flattened_params:
          if name in renamed_params:
              if (
                  flattened_params[name].shape
                  == renamed_params[name].shape
              ):
                  flattened_params[name] = renamed_params[name]
              else:
                  logging.warning(
                      "Shapes for %s do not match. %s vs %s",
                      name,
                      flattened_params[name].shape,
                      renamed_params[name].shape,
                  )
          else:
              logging.info(
                  "%s in target model not being initialised", name
              )
  
      for name in renamed_params:
          if name not in flattened_params:
              logging.info("%s not being restored.", name)
  
      params = _unflatten(flattened_params)
      return params
  
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 7 for calling a global function with example usage: initialise_from_separate_encoders(params, restored_params, config, restored_model_cfg) and returns: params