    def by_idx(self, idx: list, freeze: bool = True):
        """
        Freeze/unfreeze layers by indexes

        Args:
            idx (`list`):
                a list of layer indexes
            freeze (`bool`):
                if or not freeze layers (default: True)
        """
        for i in idx:
            for param in list(self.model.children())[i].parameters():
                param.requires_grad = not freeze
Freeze/unfreeze layers by indexes

Args:
idx (`list`):
a list of layer indexes
freeze (`bool`):
if or not freeze layers (default: True)
towhee/trainer/utils/layer_freezer.py