class_docstr: Utilities to freeze/unfreeze layers.
  
  Args:
      model:
          a model with weights.
  Return:
      LayerFreezer.
  
  Example:
      >>> from towhee.trainer.utils.layer_freezer import LayerFreezer
      >>> from towhee.models import vit
      >>> my_model = vit.create_model()
      >>> my_freezer = LayerFreezer(my_model)
      >>> # Check if modules in the last layer are frozen
      >>> my_freezer.status(-1)
      >>> # Check if modules in the layer "head" are frozen
      >>> my_freezer.status("head")
      ['unfrozen', 'unfrozen']
      >>> # Show all frozen layers
      >>> my_freezer.show_frozen_layers()
      ['patch_embed', 'head']
      >>> # Freeze layers by a list of layer indexes
      >>> my_freezer.by_idx([0, -1])
      >>> # Freeze layers by a list of layer names
      >>> my_freezer.by_names(['head'])
      >>> # Freeze all layers
      >>> my_freezer.set_all()
      >>> # Unfreeze all layers
      >>> my_freezer.set_all(freeze=False)
      >>> # Freeze all except the last layer
      >>> my_freezer.set_slice(-1)
docstr: Check if a layer is frozen or not by its name or index
  
  Args:
      layer (`Union[str, int]`):
          the name or index of layer.
  Return:
      A list of status ('frozen' or 'unfrozen') to indicate if modules in the layer are frozen or not.
code: def status(self, layer: Union[str, int]):
      """
      Check if a layer is frozen or not by its name or index
  
      Args:
          layer (`Union[str, int]`):
              the name or index of layer.
      Return:
          A list of status ('frozen' or 'unfrozen') to indicate if modules in the layer are frozen or not.
      """
      if isinstance(layer, str):
          if layer not in self.layer_names:
              raise ValueError(f"Layer does not exist: {layer}")
          for name, child in self.model.named_children():
              if name == layer:
                  outs = []
                  for param in child.parameters():
                      outs.append(
                          "unfrozen"
                          if param.requires_grad
                          else "frozen"
                      )
                  print(f"Freeze status of layer {layer}: {outs}")
                  return outs
      if isinstance(layer, int):
          outs = []
          for param in list(self.model.children())[layer].parameters():
              outs.append(
                  "unfrozen" if param.requires_grad else "frozen"
              )
          print(f"Freeze status of layer {layer}: {outs}")
          return outs
  
file_path: towhee/towhee/trainer/utils/layer_freezer.py
imports: from typing import Union
label_desc: Use image node_id 2 for calling the LayerFreezer obj's underlying member method code with example usage: obj.status(layer) and returns: outs, outs