-
Notifications
You must be signed in to change notification settings - Fork 7.2k
using np.random.RandomState(seed)
instead of np.random.seed(seed)
#4250
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
193b3b6
using np.random.RandomState(seed) instead of np.random.seed(seed)
d5dda53
using np.random.RandomState(seed) instead of np.random.seed(seed)
6659e82
passing random_state_numpy to inception_v3
31bd6e3
Merge branch 'np_randomstate' of https://github.com/vmoens/vision int…
746d612
reverting inception random_state kwarg
65dcd02
reverting inception random_state kwarg
d715cb4
Merge branch 'np_randomstate' of https://github.com/vmoens/vision int…
6e22a1d
move np_rng locally
47cbd1c
move np_rng locally
0aeac4d
Merge branch 'np_randomstate' of https://github.com/vmoens/vision int…
778dea9
Merge commit '7e987bfde253cf457f5f6d4d1c35c560f1711a00' into np_rando…
674b4b1
removing np random seed from test/common_utils.py
5b0a71b
minor
5511cdd
Merge branch 'master' into np_randomstate
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -200,18 +200,19 @@ class TestToTensor: | |
def test_to_tensor(self, channels): | ||
height, width = 4, 4 | ||
trans = transforms.ToTensor() | ||
np_rng = np.random.RandomState(0) | ||
|
||
input_data = torch.ByteTensor(channels, height, width).random_(0, 255).float().div_(255) | ||
img = transforms.ToPILImage()(input_data) | ||
output = trans(img) | ||
torch.testing.assert_close(output, input_data) | ||
|
||
ndarray = np.random.randint(low=0, high=255, size=(height, width, channels)).astype(np.uint8) | ||
ndarray = np_rng.randint(low=0, high=255, size=(height, width, channels)).astype(np.uint8) | ||
output = trans(ndarray) | ||
expected_output = ndarray.transpose((2, 0, 1)) / 255.0 | ||
torch.testing.assert_close(output.numpy(), expected_output, check_dtype=False) | ||
|
||
ndarray = np.random.rand(height, width, channels).astype(np.float32) | ||
ndarray = np_rng.rand(height, width, channels).astype(np.float32) | ||
output = trans(ndarray) | ||
expected_output = ndarray.transpose((2, 0, 1)) | ||
torch.testing.assert_close(output.numpy(), expected_output, check_dtype=False) | ||
|
@@ -225,22 +226,24 @@ def test_to_tensor(self, channels): | |
def test_to_tensor_errors(self): | ||
height, width = 4, 4 | ||
trans = transforms.ToTensor() | ||
np_rng = np.random.RandomState(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove this one too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think they come from a rather chaotic |
||
|
||
with pytest.raises(TypeError): | ||
trans(np.random.rand(1, height, width).tolist()) | ||
trans(np_rng.rand(1, height, width).tolist()) | ||
|
||
with pytest.raises(ValueError): | ||
trans(np.random.rand(height)) | ||
trans(np_rng.rand(height)) | ||
|
||
with pytest.raises(ValueError): | ||
trans(np.random.rand(1, 1, height, width)) | ||
trans(np_rng.rand(1, 1, height, width)) | ||
|
||
@pytest.mark.parametrize('dtype', [torch.float16, torch.float, torch.double]) | ||
def test_to_tensor_with_other_default_dtypes(self, dtype): | ||
np_rng = np.random.RandomState(0) | ||
current_def_dtype = torch.get_default_dtype() | ||
|
||
t = transforms.ToTensor() | ||
np_arr = np.random.randint(0, 255, (32, 32, 3), dtype=np.uint8) | ||
np_arr = np_rng.randint(0, 255, (32, 32, 3), dtype=np.uint8) | ||
img = Image.fromarray(np_arr) | ||
|
||
torch.set_default_dtype(dtype) | ||
|
@@ -253,19 +256,20 @@ def test_to_tensor_with_other_default_dtypes(self, dtype): | |
def test_pil_to_tensor(self, channels): | ||
height, width = 4, 4 | ||
trans = transforms.PILToTensor() | ||
np_rng = np.random.RandomState(0) | ||
|
||
input_data = torch.ByteTensor(channels, height, width).random_(0, 255) | ||
img = transforms.ToPILImage()(input_data) | ||
output = trans(img) | ||
torch.testing.assert_close(input_data, output) | ||
|
||
input_data = np.random.randint(low=0, high=255, size=(height, width, channels)).astype(np.uint8) | ||
input_data = np_rng.randint(low=0, high=255, size=(height, width, channels)).astype(np.uint8) | ||
img = transforms.ToPILImage()(input_data) | ||
output = trans(img) | ||
expected_output = input_data.transpose((2, 0, 1)) | ||
torch.testing.assert_close(output.numpy(), expected_output) | ||
|
||
input_data = torch.as_tensor(np.random.rand(channels, height, width).astype(np.float32)) | ||
input_data = torch.as_tensor(np_rng.rand(channels, height, width).astype(np.float32)) | ||
img = transforms.ToPILImage()(input_data) # CHW -> HWC and (* 255).byte() | ||
output = trans(img) # HWC -> CHW | ||
expected_output = (input_data * 255).byte() | ||
|
@@ -280,12 +284,13 @@ def test_pil_to_tensor(self, channels): | |
def test_pil_to_tensor_errors(self): | ||
height, width = 4, 4 | ||
trans = transforms.PILToTensor() | ||
np_rng = np.random.RandomState(0) | ||
|
||
with pytest.raises(TypeError): | ||
trans(np.random.rand(1, height, width).tolist()) | ||
trans(np_rng.rand(1, height, width).tolist()) | ||
|
||
with pytest.raises(TypeError): | ||
trans(np.random.rand(1, height, width)) | ||
trans(np_rng.rand(1, height, width)) | ||
|
||
|
||
def test_randomresized_params(): | ||
|
@@ -1180,10 +1185,11 @@ def test_random_grayscale(): | |
"""Unit tests for random grayscale transform""" | ||
|
||
# Test Set 1: RGB -> 3 channel grayscale | ||
np_rng = np.random.RandomState(0) | ||
random_state = random.getstate() | ||
random.seed(42) | ||
x_shape = [2, 2, 3] | ||
x_np = np.random.randint(0, 256, x_shape, np.uint8) | ||
x_np = np_rng.randint(0, 256, x_shape, np.uint8) | ||
x_pil = Image.fromarray(x_np, mode='RGB') | ||
x_pil_2 = x_pil.convert('L') | ||
gray_np = np.array(x_pil_2) | ||
|
@@ -1206,7 +1212,7 @@ def test_random_grayscale(): | |
random_state = random.getstate() | ||
random.seed(42) | ||
x_shape = [2, 2, 3] | ||
x_np = np.random.randint(0, 256, x_shape, np.uint8) | ||
x_np = np_rng.randint(0, 256, x_shape, np.uint8) | ||
x_pil = Image.fromarray(x_np, mode='RGB') | ||
x_pil_2 = x_pil.convert('L') | ||
gray_np = np.array(x_pil_2) | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this one, as you're already declaring another RandomState below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad yeah i missed that one