Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tuned Faster R-CNN model detect maximum 100 objects, but there is 300+ objects on the image. How to increase this maximum?

I use this code to prepare model for optimization:

# load Faster RCNN pre-trained model
Faster_RCNN_tuned_model = torchvision.models.detection.fasterrcnn_resnet50_fpn(weights="DEFAULT")

# Get the number of input features 
in_features = Faster_RCNN_tuned_model.roi_heads.box_predictor.cls_score.in_features
    
# Define a new head for the detector with 2 classes (cell or fone)
Faster_RCNN_tuned_model.roi_heads.box_predictor = FastRCNNPredictor(in_features, 2) 
Faster_RCNN_tuned_model = Faster_RCNN_tuned_model.to(DEVICE)

and this code to load tuned model:

# Create Faster RCNN default model
best_Faster_RCNN_tuned_model = torchvision.models.detection.fasterrcnn_resnet50_fpn(weights="DEFAULT")
# Get the number of input features 
in_features = best_Faster_RCNN_tuned_model.roi_heads.box_predictor.cls_score.in_features
    
# Define a new head for the detector with 2 classes (cell or fone)
best_Faster_RCNN_tuned_model.roi_heads.box_predictor = FastRCNNPredictor(in_features, 2) 
# Load and setup parameters from saved best model
checkpoint = torch.load('C:\\temp\\datasets\\mediag\\models\\best_model.pth', map_location=DEVICE)
best_Faster_RCNN_tuned_model.load_state_dict(checkpoint['model_state_dict'])
best_Faster_RCNN_tuned_model = best_Faster_RCNN_tuned_model.to(DEVICE).eval()

There is 300+ objects on the images, but model detects only 100 objects:
Show objects count for first 5 images

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I increase maximum objects count up to 3000 ?

May be I should manually setup this parameter ?

in_features = best_Faster_RCNN_tuned_model.roi_heads.box_predictor.cls_score.in_features
    
# Define a new head for the detector with 2 classes (cell or fone)
best_Faster_RCNN_tuned_model.roi_heads.box_predictor = FastRCNNPredictor(in_features, 2) 

Please help me to increase detected objects count.

>Solution :

I think it might help you to set the box_detections_per_img=300 when creating the model.
This might be helpful: https://discuss.pytorch.org/t/faster-rcnn-yields-hundred-maches-every-time/100279/3

Also see the following parameters for better detections:
https://github.com/pytorch/vision/blob/6e639d3e49371a509235201cb3f335b1c5cac0e3/torchvision/models/detection/faster_rcnn.py#L67-L88

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading