Skip to content

Commit

Permalink
fix cropping to include last column and last row (#2384)
Browse files Browse the repository at this point in the history
  • Loading branch information
arunppsg authored Jun 2, 2023
1 parent 64dc702 commit 5b804b8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions beginner_source/data_loading_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ def __call__(self, sample):
h, w = image.shape[:2]
new_h, new_w = self.output_size

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

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

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

0 comments on commit 5b804b8

Please sign in to comment.