def test_to_tensor(): var_x = Variable(torch.Tensor([0.0])) x = to_tensor(var_x) assert torch.is_tensor(x) var_x = (Variable(torch.Tensor([0.0])), Variable(torch.Tensor([0.0]))) x = to_tensor(var_x) assert isinstance(x, list) and torch.is_tensor(x[0]) and torch.is_tensor(x[1]) var_x = {'a': Variable(torch.Tensor([0.0])), 'b': Variable(torch.Tensor([0.0]))} x = to_tensor(var_x) assert isinstance(x, dict) and torch.is_tensor(x['a']) and torch.is_tensor(x['b']) with pytest.raises(TypeError): to_tensor(12345)
def _inference(batch): model.eval() x, y = _prepare_batch(batch) y_pred = model(x) return to_tensor(y_pred, cpu=not cuda), to_tensor(y, cpu=not cuda)
def _inference(engine, batch): model.eval() # x, y = _prepare_batch(batch, cuda, volatile=True) y = batch.label y_pred, _ = model(batch) return to_tensor(y_pred, cpu=not cuda), to_tensor(y, cpu=not cuda)