Skip to content

Commit 5b804b8

Browse files
authored
fix cropping to include last column and last row (#2384)
1 parent 64dc702 commit 5b804b8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: beginner_source/data_loading_tutorial.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ def __call__(self, sample):
268268
h, w = image.shape[:2]
269269
new_h, new_w = self.output_size
270270

271-
top = np.random.randint(0, h - new_h)
272-
left = np.random.randint(0, w - new_w)
271+
top = np.random.randint(0, h - new_h + 1)
272+
left = np.random.randint(0, w - new_w + 1)
273273

274274
image = image[top: top + new_h,
275275
left: left + new_w]
@@ -294,7 +294,7 @@ def __call__(self, sample):
294294

295295
######################################################################
296296
# .. note::
297-
# In the example above, `RandomCrop` uses an external library's random number generator
297+
# In the example above, `RandomCrop` uses an external library's random number generator
298298
# (in this case, Numpy's `np.random.int`). This can result in unexpected behavior with `DataLoader`
299299
# (see `here <https://pytorch.org/docs/stable/notes/faq.html#my-data-loader-workers-return-identical-random-numbers>`_).
300300
# In practice, it is safer to stick to PyTorch's random number generator, e.g. by using `torch.randint` instead.

0 commit comments

Comments
 (0)