A complete Mask R-CNN pipeline for object detection and instance segmentation on the COCO dataset, with visualization and mAP evaluation using PyTorch.
Welcome to the Mask R-CNN Vision Suite! This project demonstrates object detection and instance segmentation using the pretrained Mask R-CNN (ResNet-50 FPN) model on the COCO val2017 dataset. The system visualizes predictions, applies segmentation masks, and evaluates performance using mAP (mean Average Precision) via the COCO evaluation API.
The Mask R-CNN Vision Suite project aims to showcase a complete end-to-end pipeline for object detection and instance segmentation using a pretrained model. It loads the COCO validation dataset, performs inference, visualizes results with masks and bounding boxes, and computes evaluation metrics using pycocotools.
The project is organized into clear, functional components for a smooth workflow:
- Notebook: A Jupyter Notebook that guides you through loading data, running inference, and evaluating results.
- Setup: Instructions for installing dependencies and downloading the COCO dataset.
- Model: Utilizes PyTorch's pretrained maskrcnn_resnet50_fpn from torchvision.models.detection.
- Evaluation: Uses COCOeval from pycocotools for calculating mAP scores.
- Visualization: Displays bounding boxes and masks over real COCO images using OpenCV and Matplotlib.
- Object Detection with bounding boxes
- Instance Segmentation using mask overlays
- mAP Evaluation using COCO API (pycocotools)
- Pretrained Mask R-CNN (ResNet-50 FPN backbone)
- Visualization with OpenCV + Matplotlib
- Auto-download COCO annotations & images
Follow these steps to get started:
git clone "https://github.com/nshahmeer-ai/maskrcnn-vision-suite-detection-segmentation"
cd maskrcnn-object-detection-segmentation
python -m venv maskrcnn-env
source maskrcnn-env/bin/activate # for Linux/macOS
maskrcnn-env\Scripts\activate # for Windows
pip install -r requirements.txt
jupyter notebook
Open MaskRCNN_COCO_Inference.ipynb and follow the cells step by step.
The notebook will automatically download:
- COCO 2017 Annotations (instances_val2017.json)
- COCO Validation Images (val2017)
If already present, the download is skipped.
After inference, the results are saved in coco_results.json.
Then COCOeval from pycocotools is used to calculate:
- AP@[IoU=.50:.95] (mAP)
- AP@IoU=0.5
- AR (Average Recall)
These are standard metrics used for benchmarking models on COCO.
Bounding boxes and masks are drawn over original images:
- Green rectangles: Detected objects
- Red masks: Segmented regions
- White text: Class IDs
Matplotlib is used to render the final visualization.
- PyTorch and TorchVision
- Mask R-CNN (ResNet-50 FPN)
- pycocotools (COCO evaluation API)
- OpenCV, Matplotlib, Pillow, NumPy
To test your own image or a different COCO image, change the image ID in the notebook:
img_ids = coco.getImgIds()
img_info = coco.loadImgs(img_ids[0])[0] # change index for different image
Contributing
Star this repo Fork and PR improvements Report issues or bugs Add new model integrations or features Open to:
Remote roles (ML/DL Engineer, CV Specialist) Research internships or collaborations Open-source AI/ML contributions
About the Author Shahmeer Nawaz Master's Student in Artificial Intelligence
Email: shahmeernawazai@gmail.com GitHub: https://github.com/nshahmeer-ai LinkedIn: https://www.linkedin.com/in/shahmeernawazai