mmaction/models/recognizers/base_semi.py
def _parse_losses(losses):
        """Parse the raw outputs (losses) of the network.

        Args:
            losses (dict): Raw output of the network, which usually contain
                losses and other necessary information.

        Returns:
            tuple[Tensor, dict]: (loss, log_vars), loss is the loss tensor
                which may be a weighted sum of all losses, log_vars contains
                all the variables to be sent to the logger.
        """
        log_vars = OrderedDict()
        for loss_name, loss_value in losses.items():
            if isinstance(loss_value, torch.Tensor):
                log_vars[loss_name] = loss_value.mean()
            elif isinstance(loss_value, list):
                log_vars[loss_name] = sum(_loss.mean() for _loss in loss_value)
            else:
                raise TypeError(
                    f'{loss_name} is not a tensor or list of tensors')

        loss = sum(_value for _key, _value in log_vars.items()
                   if 'loss' in _key)

        log_vars['loss'] = loss
        if dist.is_available() and dist.is_initialized():
            loss_value = log_vars['num_select'].data.clone()
            dist.all_reduce(loss_value)
            log_vars['num_select'] = loss_value.item()

        for loss_name, loss_value in log_vars.items():
            # reduce loss when distributed training
            if dist.is_available() and dist.is_initialized():
                if loss_name == 'num_select':
                    continue

                loss_value = loss_value.data.clone()
                # NOTE: Compute unlabeled data accuracy for selected confident examples only
                if 'acc_weak' in loss_name or 'acc_strong' in loss_name:
                    dist.all_reduce(loss_value)
                    loss_value.div_(log_vars['num_select']+1e-6)
                    # TODO: A work-around. Sometimes all 0 accuracy will explode after all_reduce
                    if loss_value > 1. or loss_value < 0.:
                        loss_value = torch.zeros(1).to(loss_value.device)
                else:
                    dist.all_reduce(loss_value.div_(dist.get_world_size()))
            log_vars[loss_name] = loss_value.item()

        return loss, log_vars
Parse the raw outputs (losses) of the network.

        Args:
            losses (dict): Raw output of the network, which usually contain
                losses and other necessary information.

        Returns:
            tuple[Tensor, dict]: (loss, log_vars), loss is the loss tensor
                which may be a weighted sum of all losses, log_vars contains
                all the variables to be sent to the logger.
        
Parse the raw outputs (losses) of the network.
Parse the raw outputs ( losses ) of the network .
def _parse_losses(losses):
        log_vars = OrderedDict()
        for loss_name, loss_value in losses.items():
            if isinstance(loss_value, torch.Tensor):
                log_vars[loss_name] = loss_value.mean()
            elif isinstance(loss_value, list):
                log_vars[loss_name] = sum(_loss.mean() for _loss in loss_value)
            else:
                raise TypeError(
                    f'{loss_name} is not a tensor or list of tensors')
        loss = sum(_value for _key, _value in log_vars.items()
                   if 'loss' in _key)
        log_vars['loss'] = loss
        if dist.is_available() and dist.is_initialized():
            loss_value = log_vars['num_select'].data.clone()
            dist.all_reduce(loss_value)
            log_vars['num_select'] = loss_value.item()
        for loss_name, loss_value in log_vars.items():
            if dist.is_available() and dist.is_initialized():
                if loss_name == 'num_select':
                    continue
                loss_value = loss_value.data.clone()
                if 'acc_weak' in loss_name or 'acc_strong' in loss_name:
                    dist.all_reduce(loss_value)
                    loss_value.div_(log_vars['num_select']+1e-6)
                    if loss_value > 1. or loss_value < 0.:
                        loss_value = torch.zeros(1).to(loss_value.device)
                else:
                    dist.all_reduce(loss_value.div_(dist.get_world_size()))
            log_vars[loss_name] = loss_value.item()
        return loss, log_vars
def _parse_losses ( losses ) : log_vars = OrderedDict ( ) for loss_name , loss_value in losses . items ( ) : if isinstance ( loss_value , torch . Tensor ) : log_vars [ loss_name ] = loss_value . mean ( ) elif isinstance ( loss_value , list ) : log_vars [ loss_name ] = sum ( _loss . mean ( ) for _loss in loss_value ) else : raise TypeError ( f'{loss_name} is not a tensor or list of tensors' ) loss = sum ( _value for _key , _value in log_vars . items ( ) if 'loss' in _key ) log_vars [ 'loss' ] = loss if dist . is_available ( ) and dist . is_initialized ( ) : loss_value = log_vars [ 'num_select' ] . data . clone ( ) dist . all_reduce ( loss_value ) log_vars [ 'num_select' ] = loss_value . item ( ) for loss_name , loss_value in log_vars . items ( ) : if dist . is_available ( ) and dist . is_initialized ( ) : if loss_name == 'num_select' : continue loss_value = loss_value . data . clone ( ) if 'acc_weak' in loss_name or 'acc_strong' in loss_name : dist . all_reduce ( loss_value ) loss_value . div_ ( log_vars [ 'num_select' ] + 1e-6 ) if loss_value > 1. or loss_value < 0. : loss_value = torch . zeros ( 1 ) . to ( loss_value . device ) else : dist . all_reduce ( loss_value . div_ ( dist . get_world_size ( ) ) ) log_vars [ loss_name ] = loss_value . item ( ) return loss , log_vars
Parse the raw outputs (losses) of the network.
Parse the raw outputs ( losses ) of the network .
"""Parse the raw outputs (losses) of the network.

        Args:
            losses (dict): Raw output of the network, which usually contain
                losses and other necessary information.

        Returns:
            tuple[Tensor, dict]: (loss, log_vars), loss is the loss tensor
                which may be a weighted sum of all losses, log_vars contains
                all the variables to be sent to the logger.
        """ # reduce loss when distributed training # NOTE: Compute unlabeled data accuracy for selected confident examples only # TODO: A work-around. Sometimes all 0 accuracy will explode after all_reduce
(loss, log_vars), loss is the loss tensor
which may be a weighted sum of all losses, log_vars contains
all the variables to be sent to the logger.
( loss log_vars ) loss is the loss tensor which may be a weighted sum of all losses log_vars contains all the variables to be sent to the logger .
tuple[Tensor, dict]
losses
Raw output of the network, which usually contain
losses and other necessary information.
Raw output of the network which usually contain losses and other necessary information .