-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-write getting started guide for transforms V2 (#7870)
Co-authored-by: vfdev <vfdev.5@gmail.com> Co-authored-by: Philip Meier <github.pmeier@posteo.de>
- Loading branch information
1 parent
11e49de
commit 6f72b76
Showing
9 changed files
with
285 additions
and
161 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
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
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,33 @@ | ||
import matplotlib.pyplot as plt | ||
from torchvision.utils import draw_bounding_boxes | ||
|
||
|
||
def plot(imgs): | ||
if not isinstance(imgs[0], list): | ||
# Make a 2d grid even if there's just 1 row | ||
imgs = [imgs] | ||
|
||
num_rows = len(imgs) | ||
num_cols = len(imgs[0]) | ||
_, axs = plt.subplots(nrows=num_rows, ncols=num_cols, squeeze=False) | ||
for row_idx, row in enumerate(imgs): | ||
for col_idx, img in enumerate(row): | ||
bboxes = None | ||
if isinstance(img, tuple): | ||
bboxes = img[1] | ||
img = img[0] | ||
if isinstance(bboxes, dict): | ||
bboxes = bboxes['bboxes'] | ||
if img.dtype.is_floating_point and img.min() < 0: | ||
# Poor man's re-normalization for the colors to be OK-ish. This | ||
# is useful for images coming out of Normalize() | ||
img -= img.min() | ||
img /= img.max() | ||
|
||
if bboxes is not None: | ||
img = draw_bounding_boxes(img, bboxes, colors="yellow", width=3) | ||
ax = axs[row_idx, col_idx] | ||
ax.imshow(img.permute(1, 2, 0).numpy()) | ||
ax.set(xticklabels=[], yticklabels=[], xticks=[], yticks=[]) | ||
|
||
plt.tight_layout() |
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
Oops, something went wrong.