Skip to content

Commit a2b39cb

Browse files
committed
Updated torchvision_tutorial.py content: links, irrelevant sections etc
1 parent 10d31f6 commit a2b39cb

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

intermediate_source/torchvision_tutorial.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# The reference scripts for training object detection, instance
2929
# segmentation and person keypoint detection allows for easily supporting
3030
# adding new custom datasets. The dataset should inherit from the standard
31-
# ``torch.utils.data.Dataset`` class, and implement ``__len__`` and
31+
# :class:`torch.utils.data.Dataset` class, and implement ``__len__`` and
3232
# ``__getitem__``.
3333
#
3434
# The only specificity that we require is that the dataset ``__getitem__``
@@ -105,21 +105,33 @@
105105
# FudanPed00004.png
106106
#
107107
# Here is one example of a pair of images and segmentation masks
108-
#
109-
# .. image:: ../../_static/img/tv_tutorial/tv_image01.png
110-
#
111-
# .. image:: ../../_static/img/tv_tutorial/tv_image02.png
112-
#
108+
109+
import matplotlib.pyplot as plt
110+
from torchvision.io import read_image
111+
112+
113+
image = read_image("data/PennFudanPed/PNGImages/FudanPed00046.png")
114+
mask = read_image("data/PennFudanPed/PedMasks/FudanPed00046_mask.png")
115+
116+
plt.figure(figsize=(16, 8))
117+
plt.subplot(121)
118+
plt.title("Image")
119+
plt.imshow(image.permute(1, 2, 0))
120+
plt.subplot(122)
121+
plt.title("Mask")
122+
plt.imshow(mask.permute(1, 2, 0))
123+
124+
######################################################################
113125
# So each image has a corresponding
114126
# segmentation mask, where each color correspond to a different instance.
115127
# Let’s write a :class:`torch.utils.data.Dataset` class for this dataset.
116128
# In the code below, we are wrapping images, bounding boxes and masks into
117-
# ``torchvision.TVTensor`` classes so that we will be able to apply torchvision
129+
# :class:`torchvision.tv_tensors.TVTensor` classes so that we will be able to apply torchvision
118130
# built-in transformations (`new Transforms API <https://pytorch.org/vision/stable/transforms.html>`_)
119131
# for the given object detection and segmentation task.
120132
# Namely, image tensors will be wrapped by :class:`torchvision.tv_tensors.Image`, bounding boxes into
121133
# :class:`torchvision.tv_tensors.BoundingBoxes` and masks into :class:`torchvision.tv_tensors.Mask`.
122-
# As ``torchvision.TVTensor`` are :class:`torch.Tensor` subclasses, wrapped objects are also tensors and inherit the plain
134+
# As :class:`torchvision.tv_tensors.TVTensor` are :class:`torch.Tensor` subclasses, wrapped objects are also tensors and inherit the plain
123135
# :class:`torch.Tensor` API. For more information about torchvision ``tv_tensors`` see
124136
# `this documentation <https://pytorch.org/vision/main/auto_examples/transforms/plot_transforms_getting_started.html#what-are-tvtensors>`_.
125137

@@ -476,8 +488,6 @@ def get_transform(train):
476488
# But what do the predictions look like? Let’s take one image in the
477489
# dataset and verify
478490
#
479-
# .. image:: ../../_static/img/tv_tutorial/tv_image05.png
480-
#
481491
import matplotlib.pyplot as plt
482492

483493
from torchvision.utils import draw_bounding_boxes, draw_segmentation_masks
@@ -516,7 +526,7 @@ def get_transform(train):
516526
#
517527
# In this tutorial, you have learned how to create your own training
518528
# pipeline for object detection models on a custom dataset. For
519-
# that, you wrote a ``torch.utils.data.Dataset`` class that returns the
529+
# that, you wrote a :class:`torch.utils.data.Dataset` class that returns the
520530
# images and the ground truth boxes and segmentation masks. You also
521531
# leveraged a Mask R-CNN model pre-trained on COCO train2017 in order to
522532
# perform transfer learning on this new dataset.
@@ -525,5 +535,3 @@ def get_transform(train):
525535
# training, check ``references/detection/train.py``, which is present in
526536
# the torchvision repository.
527537
#
528-
# You can download a full source file for this tutorial
529-
# `here <https://pytorch.org/tutorials/_static/tv-training-code.py>`_.

0 commit comments

Comments
 (0)