    def by_names(self, names: list, freeze: bool = True):
        """
        Freeze/unfreeze layers by names

        Args:
            names (`list`):
                a list of layer names
            freeze (`bool`):
                if or not freeze layers (default: True)
        """
        if not set(names).issubset(set(self.layer_names)):
            invalid_names = set(names) - set(self.layer_names)
            raise ValueError(f'Layer does not exist: {invalid_names}')
        for name, layer in self.model.named_children():
            if name not in names:
                pass
            else:
                for param in layer.parameters():
                    param.requires_grad = not freeze
Freeze/unfreeze layers by names

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