code: def load_weights_from_hdf5_group_by_name(
      f, model, skip_mismatch=False
  ):
      """Implements name-based weight loading (instead of topological loading).
  
      Layers that have no matching name are skipped.
  
      Args:
          f: A pointer to a HDF5 group.
          model: Model instance.
          skip_mismatch: Boolean, whether to skip loading of layers
              where there is a mismatch in the number of weights,
              or a mismatch in the shape of the weights.
  
      Raises:
          ValueError: in case of mismatch between provided layers
              and weights file and skip_match=False.
      """
      if "keras_version" in f.attrs:
          original_keras_version = f.attrs["keras_version"]
          if hasattr(original_keras_version, "decode"):
              original_keras_version = original_keras_version.decode(
                  "utf8"
              )
      else:
          original_keras_version = "1"
      if "backend" in f.attrs:
          original_backend = f.attrs["backend"]
          if hasattr(original_backend, "decode"):
              original_backend = original_backend.decode("utf8")
      else:
          original_backend = None
  
      # New file format.
      layer_names = load_attributes_from_hdf5_group(f, "layer_names")
  
      # Reverse index of layer name to list of layers with name.
      index = {}
      for layer in model.layers:
          if layer.name:
              index.setdefault(layer.name, []).append(layer)
  
      for k, name in enumerate(layer_names):
          g = f[name]
          weight_values = load_subset_weights_from_hdf5_group(g)
          for layer in index.get(name, []):
              symbolic_weights = _legacy_weights(layer)
              if len(weight_values) != len(symbolic_weights):
                  if skip_mismatch:
                      warnings.warn(
                          f"Skipping loading of weights for layer #{k} (named "
                          f"{layer.name}) due to mismatch in number of weights. "
                          f"Layer expects {len(symbolic_weights)} weight(s). "
                          f"Received {len(weight_values)} saved weight(s)",
                          stacklevel=2,
                      )
                      continue
                  raise ValueError(
                      f"Weight count mismatch for layer #{k} "
                      f"(named {layer.name}). "
                      f"Layer expects {len(symbolic_weights)} weight(s). "
                      f"Received {len(weight_values)} saved weight(s)"
                  )
              # Set values.
              for i in range(len(weight_values)):
                  expected_shape = symbolic_weights[i].shape
                  received_shape = weight_values[i].shape
                  if expected_shape != received_shape:
                      if skip_mismatch:
                          warnings.warn(
                              f"Skipping loading weights for layer #{k} (named "
                              f"{layer.name}) due to mismatch in shape for "
                              f"weight {symbolic_weights[i].name}. "
                              f"Weight expects shape {expected_shape}. "
                              "Received saved weight "
                              f"with shape {received_shape}",
                              stacklevel=2,
                          )
                          continue
                      raise ValueError(
                          f"Shape mismatch in layer #{k} (named {layer.name}) "
                          f"for weight {symbolic_weights[i].name}. "
                          f"Weight expects shape {expected_shape}. "
                          "Received saved weight "
                          f"with shape {received_shape}"
                      )
                  else:
                      symbolic_weights[i].assign(weight_values[i])
  
      if "top_level_model_weights" in f:
          symbolic_weights = (
              model.trainable_weights + model.non_trainable_weights
          )
          weight_values = load_subset_weights_from_hdf5_group(
              f["top_level_model_weights"]
          )
  
          if len(weight_values) != len(symbolic_weights):
              if skip_mismatch:
                  warnings.warn(
                      "Skipping loading top-level weights for model due to "
                      "mismatch in number of weights. "
                      f"Model expects {len(symbolic_weights)} "
                      "top-level weight(s). "
                      f"Received {len(weight_values)} saved top-level weight(s)",
                      stacklevel=2,
                  )
              else:
                  raise ValueError(
                      "Weight count mismatch for top-level weights of model. "
                      f"Model expects {len(symbolic_weights)} "
                      "top-level weight(s). "
                      f"Received {len(weight_values)} saved top-level weight(s)"
                  )
          else:
              for i in range(len(weight_values)):
                  expected_shape = symbolic_weights[i].shape
                  received_shape = weight_values[i].shape
                  if expected_shape != received_shape:
                      if skip_mismatch:
                          warnings.warn(
                              "Skipping loading top-level weight for model due "
                              "to mismatch in shape for "
                              f"weight {symbolic_weights[i].name}. "
                              f"Weight expects shape {expected_shape}. "
                              "Received saved weight "
                              f"with shape {received_shape}",
                              stacklevel=2,
                          )
                      else:
                          raise ValueError(
                              "Shape mismatch in model for top-level weight "
                              f"{symbolic_weights[i].name}. "
                              f"Weight expects shape {expected_shape}. "
                              "Received saved weight "
                              f"with shape {received_shape}"
                          )
                  else:
                      symbolic_weights[i].assign(weight_values[i])
  
imports: import json
  import os
  import warnings
  import numpy
  from absl import logging
  from keras import backend
  from keras import optimizers
  from keras.backend.common import global_state
  from keras.legacy.saving import json_utils
  from keras.legacy.saving import saving_options
  from keras.legacy.saving import saving_utils
  from keras.saving import object_registration
  from keras.utils import io_utils
label_desc: Use image node_id 8 for calling a global function with example usage: load_weights_from_hdf5_group_by_name(f, model, skip_mismatch) without return types