Пример #1
0
def test_img_normalize():
    dummy_tensor = torch.rand(3, 64, 64).add_(-0.5).div_(0.5)

    normalized_tensor = img_normalize(dummy_tensor)
    assert normalized_tensor.min() == 0
    assert normalized_tensor.max() == 1

    dummy_tensor = torch.randn(3, 8, 8)
    normalized_tensor = img_normalize(dummy_tensor, val_range=(-2, 2))
    assert normalized_tensor.min() < 0
    assert normalized_tensor.max() > 1

    dummy_zero_tensor = torch.zeros(8, 8)
    img_normalize(dummy_zero_tensor)
Пример #2
0
def test_img_normalize():
    dummy_img_tensor = torch.rand(3, 64, 64)
    transformed_tensor = dummy_img_tensor.add_(-0.5).div_(0.5)
    normalized_tensor = img_normalize(transformed_tensor)
    assert normalized_tensor.min() == 0
    assert normalized_tensor.max() == 1

    normalized_var = img_normalize(to_var(dummy_img_tensor))
    assert normalized_var.data.min() == 0
    assert normalized_var.data.max() == 1

    dummy_tensor = torch.LongTensor(3, 8, 8).random_(-2, to=2).float()
    normalized_tensor = img_normalize(dummy_tensor, img_range=(-2, 2))
    assert normalized_tensor.min() >= 0
    assert normalized_tensor.max() <= 1

    dummy_zero_tensor = torch.zeros(8, 8)
    img_normalize(dummy_zero_tensor)
Пример #3
0
 def image(self, kw_images, epoch, prefix):
     '''
         Args:
             kw_images: 4-D tensor [batch, channel, height, width]
             epoch: step for TensorBoard logging
             prefix: prefix string for tag
     '''
     [
         self.writer.add_image(
             f'{prefix}{tag}/{self._tag_base_counter + i}',
             img_normalize(image), epoch)
         for tag, images in kw_images.items()
         for i, image in enumerate(images)
     ]
Пример #4
0
def test_psnr():
    dummy_output = to_var(img_normalize(torch.rand(4, 3, 64, 64)))
    dummy_target = to_var(img_normalize(torch.rand(4, 3, 64, 64)))

    psnr = onegan.metrics.psnr(dummy_output, dummy_target)
    assert psnr
Пример #5
0
 def normalize(t):
     return img_normalize(t, img_range=img_range)