-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for torchtext and torchvision (#1046)
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |