Skip to content

Commit 6044386

Browse files
committed
added sample code for fasterrcnn_resnet50_fpn (optional)
1 parent c87836d commit 6044386

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

intermediate_source/torchvision_tutorial.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,29 @@ be using Mask R-CNN:
304304
That’s it, this will make ``model`` be ready to be trained and evaluated
305305
on your custom dataset.
306306

307+
Checking the model with random tensors (Optional)
308+
---------------------------
309+
310+
Before iterating over the dataset, it's always good to see what the model
311+
expects during training and inference time with random tensors.
312+
313+
.. code:: python
314+
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
315+
images,boxes,labels = torch.rand(4,3,600,1200), torch.rand(4,11,4), torch.rand(4,11) # For Training
316+
images = list(image for image in images) # This is handled by GeneralizedRCNNTransform
317+
targets = []
318+
for i in range(len(images)):
319+
d = {}
320+
d['boxes'] = boxes[i]
321+
d['labels'] = labels[i].type(torch.int64)
322+
targets.append(d)
323+
output = model(images,targets)
324+
325+
model.eval() # For inference
326+
x = [torch.rand(3, 300, 400), torch.rand(3, 500, 400)]
327+
predictions = model(x)
328+
329+
307330
Putting everything together
308331
---------------------------
309332

0 commit comments

Comments
 (0)