Skip to content

Commit

Permalink
Add tests for torchtext and torchvision (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosbo committed Jul 19, 2021
1 parent 0638abf commit 08e5a8a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_torchtext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import unittest

from torchtext.data.metrics import bleu_score


class TestTorchtext(unittest.TestCase):
def test_bleu_score(self):
candidate = [['I', 'love', 'Kaggle', 'Notebooks']]
refs = [[['Completely', 'Different']]]

self.assertEqual(0, bleu_score(candidate, refs))

25 changes: 25 additions & 0 deletions tests/test_torchvision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest

import torch
import torchvision.transforms as transforms
import torchvision.transforms.functional as F


class TestTorchvision(unittest.TestCase):
def test_float_to_float(self):
input_dtype=torch.float32
output_dtype=torch.float64
input_image = torch.tensor((0.0, 1.0), dtype=input_dtype)
transform = transforms.ConvertImageDtype(output_dtype)
transform_script = torch.jit.script(F.convert_image_dtype)

output_image = transform(input_image)
output_image_script = transform_script(input_image, output_dtype)

# TODO(b/181966788) Uncomment after upgrade to pytorch 1.9.0 is done.
# torch.testing.assert_close(output_image_script, output_image, rtol=0.0, atol=1e-6)

actual_min, actual_max = output_image.tolist()

self.assertAlmostEqual(0, actual_min)
self.assertAlmostEqual(1, actual_max)

0 comments on commit 08e5a8a

Please sign in to comment.