Skip to content

Update test_transforms.py #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_pad_with_tuple_of_pad_values(self):

def test_pad_with_non_constant_padding_modes(self):
"""Unit tests for edge, reflect, symmetric padding"""
img = torch.zeros(3, 27, 27)
img = torch.zeros(3, 27, 27).byte()
img[:, :, 0] = 1 # Constant value added to leftmost edge
img = transforms.ToPILImage()(img)
img = F.pad(img, 1, (200, 200, 200))
Expand All @@ -255,23 +255,23 @@ def test_pad_with_non_constant_padding_modes(self):
# First 6 elements of leftmost edge in the middle of the image, values are in order:
# edge_pad, edge_pad, edge_pad, constant_pad, constant value added to leftmost edge, 0
edge_middle_slice = np.asarray(edge_padded_img).transpose(2, 0, 1)[0][17][:6]
assert np.all(edge_middle_slice == np.asarray([200, 200, 200, 200, 255, 0]))
assert np.all(edge_middle_slice == np.asarray([200, 200, 200, 200, 1, 0]))
assert transforms.ToTensor()(edge_padded_img).size() == (3, 35, 35)

# Pad 3 to left/right, 2 to top/bottom
reflect_padded_img = F.pad(img, (3, 2), padding_mode='reflect')
# First 6 elements of leftmost edge in the middle of the image, values are in order:
# reflect_pad, reflect_pad, reflect_pad, constant_pad, constant value added to leftmost edge, 0
reflect_middle_slice = np.asarray(reflect_padded_img).transpose(2, 0, 1)[0][17][:6]
assert np.all(reflect_middle_slice == np.asarray([0, 0, 255, 200, 255, 0]))
assert np.all(reflect_middle_slice == np.asarray([0, 0, 1, 200, 1, 0]))
assert transforms.ToTensor()(reflect_padded_img).size() == (3, 33, 35)

# Pad 3 to left, 2 to top, 2 to right, 1 to bottom
symmetric_padded_img = F.pad(img, (3, 2, 2, 1), padding_mode='symmetric')
# First 6 elements of leftmost edge in the middle of the image, values are in order:
# sym_pad, sym_pad, sym_pad, constant_pad, constant value added to leftmost edge, 0
symmetric_middle_slice = np.asarray(symmetric_padded_img).transpose(2, 0, 1)[0][17][:6]
assert np.all(symmetric_middle_slice == np.asarray([0, 255, 200, 200, 255, 0]))
assert np.all(symmetric_middle_slice == np.asarray([0, 1, 200, 200, 1, 0]))
assert transforms.ToTensor()(symmetric_padded_img).size() == (3, 32, 34)

def test_pad_raises_with_invalid_pad_sequence_len(self):
Expand Down