Ejemplo n.º 1
0
def test_create_variable(VariableMock):
  v = np.arange(0, 3)

  with mock.patch("fastai.core.IS_TORCH_04", True):
    core.create_variable(v, volatile=True)
    assert VariableMock.call_args[1] == {"requires_grad": False}
  
  with mock.patch("fastai.core.IS_TORCH_04", False):
    core.create_variable(v, volatile=True)
    assert VariableMock.call_args[1] == {"requires_grad": False, "volatile": True}
Ejemplo n.º 2
0
def test_create_variable(VariableMock):
  v = np.arange(0, 3)

  with mock.patch("fastai.core.IS_TORCH_04", True):
    core.create_variable(v, volatile=True)
    assert VariableMock.call_args[1] == {"requires_grad": False}
  
  with mock.patch("fastai.core.IS_TORCH_04", False):
    core.create_variable(v, volatile=True)
    assert VariableMock.call_args[1] == {"requires_grad": False, "volatile": True}
Ejemplo n.º 3
0
def test_create_variable_passing_Variable_object():
    v = torch.autograd.Variable(core.T(np.arange(0, 3)))
    cv = core.create_variable(v, volatile=True)
    if core.IS_TORCH_04:
        assert (cv == v).all()
    else:
        assert cv is v
def image_loader(image_name: str, image_size: int):
    """load image, returns cuda tensor"""
    loader = get_loader(image_size)
    image = Image.open(image_name)
    image = loader(image).float()
    image = create_variable(image, True, requires_grad=False)
    image = image.unsqueeze(0)
    return image
Ejemplo n.º 5
0
def test_create_variable_passing_Variable_object():
    v = torch.autograd.Variable(core.T(np.arange(0, 3)))
    assert core.create_variable(v, volatile=True) is v
Ejemplo n.º 6
0
def test_create_variable_passing_Variable_object():
  v = torch.autograd.Variable(core.T(np.arange(0, 3)))
  cv = core.create_variable(v, volatile=True)
  if core.IS_TORCH_04: assert (cv == v).all()
  else: assert cv is v