def reduce_loss(losses_reduce, op='min'):
    """
    Combine loss

    Parameters
    ----------
    losses_reduce : list of torch.Tensor [B,?,H,W]

    op: 'mean' or 'min'

    Returns
    -------
    loss_reduced : torch.Tensor [1]
        Reduced loss
    """

    # Reduce function
    def reduce_function(losses):
        if op == 'mean':
            return losses.mean()
        elif op == 'min':
            return losses.min(1, True)[0].mean()
        else:
            raise NotImplementedError(
                'Unknown photometric_reduce_op: {}'.format(op))

    # Reduce loss
    loss_reduced = sum([reduce_function(losses_reduce[i])
                            for i in range(len(losses_reduce))]) / len(losses_reduce)
    return loss_reduced