(model, criterion, dataloader)
return losses.avg
Computes loss on given dataset.
  
    :param model: PyTorch model
    :type model: `torch.nn.Module`
    :param loss_fn: Loss function
    :param dataloader: Data loader to use
    :return: Loss
    :rtype: `float`
Computes loss on given dataset.
  
    :param model: PyTorch model
    :type model: `torch.nn.Module`
    :param loss_fn: Loss function
    :param dataloader: Data loader to use
    :return: Loss
    :rtype: `float`
Computes loss on given dataset . : param model : PyTorch model : type model : torch . nn . Module : param loss_fn : Loss function : param dataloader : Data loader to use : return : Loss : rtype : float
def loss(model, criterion, dataloader):
    """
    Computes loss on given dataset.
  
    :param model: PyTorch model
    :type model: `torch.nn.Module`
    :param loss_fn: Loss function
    :param dataloader: Data loader to use
    :return: Loss
    :rtype: `float`
    """
    losses = AverageMeter()
    model.eval()
    pzero = list(model.parameters())[0]
    if (pzero.dtype != torch.float32 and pzero.dtype != torch.float16):
        raise NotImplementedError('Only FP16 and FP32 weights are supported')
    cast2fp16 = (isinstance(pzero, torch.HalfTensor)
                 or isinstance(pzero, torch.cuda.HalfTensor))
    loss = 0.
    with torch.no_grad():
        for input, target in dataloader:
            if torch.cuda.is_available():
                input = input.cuda(non_blocking=True)
                target = target.cuda(non_blocking=True)
            if cast2fp16:
                input = input.half()
            output = model(input)
            loss = criterion(output, target)
            losses.update(to_python_float(loss.data), input.size(0))
    return losses.avg
def loss ( model , criterion , dataloader ) : losses = AverageMeter ( ) model . eval ( ) pzero = list ( model . parameters ( ) ) [ 0 ] if ( pzero . dtype != torch . float32 and pzero . dtype != torch . float16 ) : raise NotImplementedError ( 'Only FP16 and FP32 weights are supported' ) cast2fp16 = ( isinstance ( pzero , torch . HalfTensor ) or isinstance ( pzero , torch . cuda . HalfTensor ) ) loss = 0. with torch . no_grad ( ) : for input , target in dataloader : if torch . cuda . is_available ( ) : input = input . cuda ( non_blocking = True ) target = target . cuda ( non_blocking = True ) if cast2fp16 : input = input . half ( ) output = model ( input ) loss = criterion ( output , target ) losses . update ( to_python_float ( loss . data ) , input . size ( 0 ) ) return losses . avg