예제 #1
0
파일: test_core.py 프로젝트: zetayue/fastai
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}
예제 #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}
예제 #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
예제 #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
예제 #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