original_docstring: 
      Compute loss on val or test data.
      
docstring: Compute loss on val or test data.
docstring_tokens: Compute loss on val or test data .
code: def evaluate(split, verbose=False, n_batches=None):
      '''
      Compute loss on val or test data.
      '''
      model.eval()
      loss = 0
      acc = 0
      correct = 0
      n_examples = 0
      if split == 'val':
          loader = val_loader
      elif split == 'test':
          loader = test_loader
      for batch_i, batch in enumerate(loader):
          data, target = batch
          if args.cuda:
              data, target = data.cuda(), target.cuda()
          data, target = Variable(data, volatile=True), Variable(target)
          output = model(data)
          loss += criterion(output, target).item()
          acc += (np.sum(output.cpu().data.numpy()[target.cpu().data.numpy()!=0] > 0.5) \
              + np.sum(output.cpu().data.numpy()[target.cpu().data.numpy()==0] < 0.5)) / float(args.im_size[1]*args.im_size[2])
          n_examples += output.size(0)
  
          if n_batches and (batch_i == n_batches-1):
              break
  
      loss /= n_examples
      acc /= n_examples
      return loss, acc
code_tokens: def evaluate ( split , verbose = False , n_batches = None ) : model . eval ( ) loss = 0 acc = 0 correct = 0 n_examples = 0 if split == 'val' : loader = val_loader elif split == 'test' : loader = test_loader for batch_i , batch in enumerate ( loader ) : data , target = batch if args . cuda : data , target = data . cuda ( ) , target . cuda ( ) data , target = Variable ( data , volatile = True ) , Variable ( target ) output = model ( data ) loss += criterion ( output , target ) . item ( ) acc += ( np . sum ( output . cpu ( ) . data . numpy ( ) [ target . cpu ( ) . data . numpy ( ) != 0 ] > 0.5 ) + np . sum ( output . cpu ( ) . data . numpy ( ) [ target . cpu ( ) . data . numpy ( ) == 0 ] < 0.5 ) ) / float ( args . im_size [ 1 ] * args . im_size [ 2 ] ) n_examples += output . size ( 0 ) if n_batches and ( batch_i == n_batches - 1 ) : break loss /= n_examples acc /= n_examples return loss , acc
short_docstring: Compute loss on val or test data.
short_docstring_tokens: Compute loss on val or test data .
comment: '''
      Compute loss on val or test data.
      '''