Faster RCNN | ML (original) (raw)

Faster R-CNN | ML

Last Updated : 25 Aug, 2025

Faster R-CNN is a popular deep learning model used for object detection which involves identifying and localizing objects within an image. Building on earlier models like R-CNN and Fast R-CNN, Faster R-CNN introduced a significant improvement by incorporating a Region Proposal Network (RPN) that generates object proposals directly within the model. This integration makes it faster and more accurate allowing it to detect multiple objects in real time with high precision.

faster-R-CNN

Faster R-CNN

Evolution of R-CNN Models

Lets see the evolution of R-CNN models for over years,

R-CNN (2013)

Fast R-CNN (2015)

Faster R-CNN (2015)

Post Faster R-CNN Improvements (2017 - present)

Architecture

Let's see the architecture of Faster R-CNN,

1. Backbone Network

2. Region Proposal Network (RPN)

RPN

Region Proposal Network(RPN)

1. RPN is a small network sliding over the feature map.

2. It predicts:

3. Uses anchors (predefined boxes of different scales and aspect ratios) to propose regions efficiently.

4. End-to-end training allows RPN and the detection network to share features.

3. Region of Interest(RoI) Pooling

RoI-pooling

Region of Interest Pooling

4. Detection Network

Bounding-Detection

Detection Network

Working of Faster R-CNN

Let's see the working using a sample example,

Step 1: Install the Dependencies

Python `

!pip install torch torchvision matplotlib

`

Step 2: Import Libraries

We will import the required libraries,

import torch from torchvision.models.detection import fasterrcnn_resnet50_fpn from torchvision.transforms import functional as F from PIL import Image import matplotlib.pyplot as plt import matplotlib.patches as patches

`

Step 3: Load and Preprocess Image

We will load the sample image,

Used sample can be downloaded from here.

Python `

image_path = "path_to_sample_image" image = Image.open(image_path).convert("RGB") image_tensor = F.to_tensor(image)

`

Step 4: Load Pretrained Faster R-CNN Model

model = fasterrcnn_resnet50_fpn(pretrained=True) model.eval()

`

Step 5: Model Inference and Extracting Detection Results

with torch.no_grad(): outputs = model([image_tensor])

boxes = outputs[0]['boxes'] labels = outputs[0]['labels'] scores = outputs[0]['scores']

`

Step 6: Visualize Results

We visualize the results,

fig, ax = plt.subplots(1, figsize=(12, 8)) ax.imshow(image)

for box, score in zip(boxes, scores): if score > 0.8: x1, y1, x2, y2 = box rect = patches.Rectangle((x1, y1), x2 - x1, y2 - y1, linewidth=2, edgecolor='r', facecolor='none') ax.add_patch(rect)

plt.show()

`

**Output:

faster-R-CNN

Faster R-CNN Result

Applications

Advantages of Faster R-CNN

Limitations