Skip to content

Commit 7bab5ce

Browse files
committed
Addressed review comments
1 parent 0e7021e commit 7bab5ce

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

_static/tv-training-code.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
"""
66

77
######################################################################
8+
#
9+
# .. tip::
10+
#
11+
# To get the most of this tutorial, we suggest using this
12+
# `Colab Version <https://colab.research.google.com/github/pytorch/tutorials/blob/gh-pages/_downloads/torchvision_finetuning_instance_segmentation.ipynb>`__.
13+
# This will allow you to experiment with the information presented below.
14+
#
15+
#
816
# For this tutorial, we will be finetuning a pre-trained `Mask
917
# R-CNN <https://arxiv.org/abs/1703.06870>`__ model on the `Penn-Fudan
1018
# Database for Pedestrian Detection and
@@ -17,6 +25,8 @@
1725
# .. note ::
1826
#
1927
# This tutorial works only with torchvision version >=0.16 or nightly.
28+
# If you're using torchvision<=0.15, please follow
29+
# `this tutorial instead <https://github.com/pytorch/tutorials/blob/d686b662932a380a58b7683425faa00c06bcf502/intermediate_source/torchvision_tutorial.rst>`_.
2030
#
2131
#
2232
# Defining the Dataset
@@ -252,8 +262,10 @@ def __len__(self):
252262
# ratios. We have a Tuple[Tuple[int]] because each feature
253263
# map could potentially have different sizes and
254264
# aspect ratios
255-
anchor_generator = AnchorGenerator(sizes=((32, 64, 128, 256, 512),),
256-
aspect_ratios=((0.5, 1.0, 2.0),))
265+
anchor_generator = AnchorGenerator(
266+
sizes=((32, 64, 128, 256, 512),),
267+
aspect_ratios=((0.5, 1.0, 2.0),)
268+
)
257269

258270
# let's define what are the feature maps that we will
259271
# use to perform the region of interest cropping, as well as
@@ -262,15 +274,19 @@ def __len__(self):
262274
# be [0]. More generally, the backbone should return an
263275
# ``OrderedDict[Tensor]``, and in ``featmap_names`` you can choose which
264276
# feature maps to use.
265-
roi_pooler = torchvision.ops.MultiScaleRoIAlign(featmap_names=['0'],
266-
output_size=7,
267-
sampling_ratio=2)
277+
roi_pooler = torchvision.ops.MultiScaleRoIAlign(
278+
featmap_names=['0'],
279+
output_size=7,
280+
sampling_ratio=2
281+
)
268282

269283
# put the pieces together inside a Faster-RCNN model
270-
model = FasterRCNN(backbone,
271-
num_classes=2,
272-
rpn_anchor_generator=anchor_generator,
273-
box_roi_pool=roi_pooler)
284+
model = FasterRCNN(
285+
backbone,
286+
num_classes=2,
287+
rpn_anchor_generator=anchor_generator,
288+
box_roi_pool=roi_pooler
289+
)
274290

275291
######################################################################
276292
# Object detection and instance segmentation model for PennFudan Dataset
@@ -301,9 +317,11 @@ def get_model_instance_segmentation(num_classes):
301317
in_features_mask = model.roi_heads.mask_predictor.conv5_mask.in_channels
302318
hidden_layer = 256
303319
# and replace the mask predictor with a new one
304-
model.roi_heads.mask_predictor = MaskRCNNPredictor(in_features_mask,
305-
hidden_layer,
306-
num_classes)
320+
model.roi_heads.mask_predictor = MaskRCNNPredictor(
321+
in_features_mask,
322+
hidden_layer,
323+
num_classes
324+
)
307325

308326
return model
309327

@@ -508,3 +526,5 @@ def get_transform(train):
508526
# training, check ``references/detection/train.py``, which is present in
509527
# the torchvision repository.
510528
#
529+
# You can download a full source file for this tutorial
530+
# `here <https://pytorch.org/tutorials/_static/tv-training-code.py>`__.

intermediate_source/torchvision_tutorial.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ an object detection and instance segmentation model on a custom dataset.
2020
.. note ::
2121
2222
This tutorial works only with torchvision version >=0.16 or nightly.
23+
If you're using torchvision<=0.15, please follow
24+
`this tutorial instead <https://github.com/pytorch/tutorials/blob/d686b662932a380a58b7683425faa00c06bcf502/intermediate_source/torchvision_tutorial.rst>`_.
2325
2426
2527
Defining the Dataset
@@ -631,3 +633,6 @@ perform transfer learning on this new dataset.
631633
For a more complete example, which includes multi-machine / multi-GPU
632634
training, check ``references/detection/train.py``, which is present in
633635
the torchvision repository.
636+
637+
You can download a full source file for this tutorial
638+
`here <https://pytorch.org/tutorials/_static/tv-training-code.py>`__.

0 commit comments

Comments
 (0)