    def set_loss(self, loss: Any, loss_name: str = None):
        """
        Set custom loss

        Args:
            loss (`Any`):
                User's custom loss instance.
            loss_name (`str`):
                The loss string in training config, if it is `None`, the string will be a default value.

        Examples:
            >>> from towhee.trainer.trainer import Trainer
            >>> import torchvision.models as models
            >>> import torch
            >>> model = models.resnet18()
            >>> trainer = Trainer(model)
            2022-03-01 17:34:36,873 - 8605304320 - trainer.py-trainer:173 - WARNING: No `TrainingConfig` passed.
            >>> class MyTripletLossFunc(torch.nn.Module):
            ...     def forward(self):
            ...         print('forward...')
            ...         return 0
            ...
            >>> my_loss = MyTripletLossFunc()
            >>> trainer.set_loss(my_loss)
            >>> type(trainer.loss)
            <class '__main__.MyTripletLossFunc'>
        """
        self.override_loss = True
        self.configs.loss = CUSTOM if loss_name is None else loss_name
        self.loss = loss
Set custom loss

Args:
loss (`Any`):
User's custom loss instance.
loss_name (`str`):
The loss string in training config, if it is `None`, the string will be a default value.

Examples:
>>> from towhee.trainer.trainer import Trainer
>>> import torchvision.models as models
>>> import torch
>>> model = models.resnet18()
>>> trainer = Trainer(model)
2022-03-01 17:34:36,873 - 8605304320 - trainer.py-trainer:173 - WARNING: No `TrainingConfig` passed.
>>> class MyTripletLossFunc(torch.nn.Module):
...     def forward(self):
...         print('forward...')
...         return 0
...
>>> my_loss = MyTripletLossFunc()
>>> trainer.set_loss(my_loss)
>>> type(trainer.loss)
<class '__main__.MyTripletLossFunc'>
towhee/trainer/trainer.py