28
28
# The reference scripts for training object detection, instance
29
29
# segmentation and person keypoint detection allows for easily supporting
30
30
# 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
32
32
# ``__getitem__``.
33
33
#
34
34
# The only specificity that we require is that the dataset ``__getitem__``
105
105
# FudanPed00004.png
106
106
#
107
107
# 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
+ ######################################################################
113
125
# So each image has a corresponding
114
126
# segmentation mask, where each color correspond to a different instance.
115
127
# Let’s write a :class:`torch.utils.data.Dataset` class for this dataset.
116
128
# 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
118
130
# built-in transformations (`new Transforms API <https://pytorch.org/vision/stable/transforms.html>`_)
119
131
# for the given object detection and segmentation task.
120
132
# Namely, image tensors will be wrapped by :class:`torchvision.tv_tensors.Image`, bounding boxes into
121
133
# :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
123
135
# :class:`torch.Tensor` API. For more information about torchvision ``tv_tensors`` see
124
136
# `this documentation <https://pytorch.org/vision/main/auto_examples/transforms/plot_transforms_getting_started.html#what-are-tvtensors>`_.
125
137
@@ -476,8 +488,6 @@ def get_transform(train):
476
488
# But what do the predictions look like? Let’s take one image in the
477
489
# dataset and verify
478
490
#
479
- # .. image:: ../../_static/img/tv_tutorial/tv_image05.png
480
- #
481
491
import matplotlib .pyplot as plt
482
492
483
493
from torchvision .utils import draw_bounding_boxes , draw_segmentation_masks
@@ -516,7 +526,7 @@ def get_transform(train):
516
526
#
517
527
# In this tutorial, you have learned how to create your own training
518
528
# 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
520
530
# images and the ground truth boxes and segmentation masks. You also
521
531
# leveraged a Mask R-CNN model pre-trained on COCO train2017 in order to
522
532
# perform transfer learning on this new dataset.
@@ -525,5 +535,3 @@ def get_transform(train):
525
535
# training, check ``references/detection/train.py``, which is present in
526
536
# the torchvision repository.
527
537
#
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